Best way to save game data in Unity

I am currently developing a game in unity and I want to add some sort of saving system that saves the following:

  • Locked / unlocked level.
  • The amount of money the player has.
  • Items / perks that the player has.

As you can see, the data I want to save is global, and has nothing to do with any specific scene.

How would you reccomend save this kind of data? I have heard about the EasySave asset but I don’t know if it is the right choice: it is pretty expensive and I belive that there has to be some easier, cheaper (even free) way to save the data.

I’ll appreciate any answer or consideration.

CharacterController / CameraController for Unity WebGL that doesn’t have the camera spins like crazy issue [closed]

I’m trying to adapt a game for WebGL and it seems that the setup often has the camera spin like crazy? Is there a recommended CharacterController / CameraController setup for WebGL with some ways to prevent the camera gimbal spinning like crazy?

How to make Unity ground mix up with sky

I’m building up a scene with Unity, I want the plane to extend far enough and mixed up with sky like the picture showing bellow enter image description here

The only way I can think off in unity is by creating two plane with 90 degree with each other to simulate this scene, I tried to set solid color for the sky but still there is clear gap between the ground plane and the sky, how do you manage to extend the ground far enough and mixed up with sky?

3D Object in 2D Unity Project

Is there a way to bring 3D objects into a 2D project that is using the 2D Universal pipeline for rendering light? I have some 3D objects I want to bring in to the project I’m working on, but they just get imported as pure white.

Is there a way to import 3D models into a 2D game, and keep the 2D pipeline for lighting? I’l tried a few different shaders, but if they’re not pure white they’re pink. I would like them to have shading as a 3D object, and still interact with light and rotate on all axis if possible. If it’s impossible to use a 3D object, if there was a way to at least have a 2D sprite taken from a 3D object, but still react to light as if it were 3D, that’d work too I suppose. This is what it looks like,

View post on

I’ve also tried adding 3D lights as well, but to no avail. I’m guessing the issue is because of my 2D lighting renderer, and for the record, this is what this tree looks like in a 3D project.

I have since attached a custom shader graph to it that I made, it looks okay, but it still doesn’t receive shading at all…

Thanks in advance.

Unity TextMeshPro bounds.size is wrong when hovering first time over gameobject

I have this weird issue, which I am not able to fix. This is my third attempt and I need some help. Basically I have a hover element which spawns when I hover over a gameobject. The height of the element is determined by the amount of text (TextMeshProUGUI).

The issue happens only when I hover first time, also not always (I have no clue how to reliably to reproduce it).

Here is what happens (sec 10~):

I have tried to add these everywhere and different combinations:

LayoutRebuilder.ForceRebuildLayoutImmediate(hoverElementRect); hoverElementRect.ForceUpdateRectTransforms(); Canvas.ForceUpdateCanvases(); txtMeshPro.ForceMeshUpdate(); 

They dont seem to help. I assume the problem is here:

float bgHeight = txtMeshPro.bounds.size.y + 25; 

The bounds.size.y is wrong the first time I hover, but I have no clue why.

Here is the whole code for spawning the GUI element:

public static void SpawnGeneralHoverElement(string descText, RectTransform hoverOverRect, float guiWidth) {     Canvas hoverCanvas = instance.hoverElementGeneral.GetComponent<Canvas>();     EnableCanvas(hoverCanvas);      TextMeshProUGUI txtMeshPro = hoverCanvas.GetComponentInChildren<TextMeshProUGUI>();     RectTransform hoverElementRect = hoverCanvas.GetComponentsInChildren<RectTransform>()[1];      float scale = hoverCanvas.GetComponent<RectTransform>().localScale.x;      txtMeshPro.text = descText;      // Need this to be dynamic, if I change hover element size, it will still work     float hoverElementWidth = guiWidth;      // Forces canvas update because of:     Canvas.ForceUpdateCanvases();     LayoutRebuilder.ForceRebuildLayoutImmediate(hoverElementRect);     hoverElementRect.ForceUpdateRectTransforms();     txtMeshPro.ForceMeshUpdate();      // Need this because otherwise the element spawns too far away on smaller resultions     float spawnOffset = (txtMeshPro.bounds.size.y * hoverCanvas.GetComponent<RectTransform>().localScale.x) + (Screen.height * 0.022f);      float bgHeight = txtMeshPro.bounds.size.y + 25;      hoverElementRect.position = new Vector3(hoverOverRect.position.x, hoverOverRect.position.y + spawnOffset,         hoverOverRect.position.z);      hoverElementRect.sizeDelta = new Vector2(guiWidth, bgHeight);     Debug.Log(hoverElementRect.sizeDelta);      LayoutRebuilder.ForceRebuildLayoutImmediate(hoverElementRect);     hoverElementRect.ForceUpdateRectTransforms();     Canvas.ForceUpdateCanvases();     txtMeshPro.ForceMeshUpdate();      // Slide in form left to right if off bounds, need for traps for example     float leftOffset = hoverElementRect.position.x - ((hoverElementRect.sizeDelta.x * scale) / 2);     if (leftOffset < 0) {         hoverElementRect.position = new Vector2(hoverElementRect.position.x + (leftOffset * -1) + 15, hoverElementRect.position.y);     }      // Slide in form right to left if off bounds, need for traps for example     float rightOffset = Screen.width - (hoverElementRect.position.x + ((hoverElementRect.sizeDelta.x * scale) / 2));     //Debug.Log("Screen width: " + Screen.width + "\nrightOffset: " + rightOffset);     if (rightOffset < 0) {         hoverElementRect.position = new Vector2(hoverElementRect.position.x - (rightOffset * -1) - 15, hoverElementRect.position.y);     }      LayoutRebuilder.ForceRebuildLayoutImmediate(hoverElementRect);     hoverElementRect.ForceUpdateRectTransforms();     Canvas.ForceUpdateCanvases();     txtMeshPro.ForceMeshUpdate();  } 

Unity 2018.4.25f1 Errors – error CS0118 & error CS0234

I am getting 2 errors in my c# script.

  1. Assets\scripts\playerMovement.cs(8,5): error CS0118: 'PlayerControls' is a namespace but is used like a type
  2. Assets\scripts\playerMovement.cs(4,19): error CS0234: The type or namespace name 'InputSystem' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)


using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem;  public class playerMovement : MonoBehaviour {     PlayerControls controls;     Vector2 move;     void Awake()     {         controls = new PlayerControls();          controls.Gameplay.move.performed += ctx => move = ctx.ReadValue<Vector2>();         controls.Gameplay.move.canceled += ctx => move =;     }     void Update()     {         Vector2 m = new Vector2(move.x, move.y) * Time.deltaTime;         transform.Translate(m, Space.World);     } } 

I am using the new Input System 0.2.1 in unity 2018.4.25f.

The PlayerControls script is auto-generated from an Actions Input object, and it is in the main root "Assets".

Unity cannot set precisly localPosition

I found strange behaviour when I was trying to set position.

I have this code:

private const float BaseY = -45f; private const float BaseX = 12.5f; 
var tile = new WorldTile(playableWorld.Name) {     WorldName = playableWorld.Name,      ServerState = GameServerState.Offline }; tile.Instance.transform.SetParent(gameObject.transform, false); tile.Instance.transform.localPosition = new Vector3(BaseX, BaseY, 0) 

Where the WorldTile is just wrapper class around creating GameObject, everywhere else is this working – position is perfectly set witihin parent, but when I try here to set the local position, it is not set on [12.5, -45, 0], it is set to [12.5, -295, 0].

I got this structure in Canvas, where CreatedList is element with predefined height of 500, it seems like unity is trying to center the element and then add my position to it..

If I change the height of the parent element to zero, it has the position I set.


Why is that happening when parent object has height?

I am creating object from prefab, which I set to the parent element. Here I want the created object to be exactly on Y -45px from top. How to achieve this?