Search Unity

Unity 2020.3.0f1 LTS Script Serialization Failure

Discussion in 'Editor & General Support' started by moneylife, Mar 21, 2021.

  1. moneylife

    moneylife

    Joined:
    Mar 21, 2021
    Posts:
    10
    Hi all. I have not used Unity or done any game dev in about a year. I reinstalled everything on a new computer looking to get started on a project.

    I installed Unity Hub. Via this I installed Unity 2020.3.0f1 (perhaps important I've installed the Unity editor and my projects on E: which is Nvme).

    I took the visual studio 2019 that comes with Unity installer.

    On creating a new project the only thing I've changed is the 'External Apps' part In Preferences to be Visual Studio (it was default to devenv).

    I create a cube named player. I create new cs script named PlayerMovement.cs and attach it to player as a component.

    I'm not at my pc so can't copy the exact script. But i leave it as default and add any variable eg. public float Speed;

    This is the first problem. That variable never serialize in inspector. The weird part is if I then click 'New Component' and create a new script named somedumbname.cs , the PlayerMovement script then serializes. Annoying but I carried on using this workaround. But then any changes I make to the movement script from now still don't work. I have to delete the dumb.cs and do it again.

    The second problem is even if I don't add any public variable. If I just write this line in Start()

    Debug.Log("player movement script started");


    Then log never appears. Unless I do that dumb.cs trick as mentioned above.

    I tried uninstalling vs 2019 and Unity. When I reinstalled it appeared to remember some of my changes ie. The colour tint I set for entering playmode.

    There appears to be no error or warning at anytime when opening Unity or compiling the code.

    Please help me as I really wanted to put some hefty hours into my new game idea this evening.

    Many thanks
     
    Last edited: Mar 21, 2021
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    I'm not really sure what you mean by that.

    - Unity will serialize a scene or prefab
    - A scene or prefab has GameObjects
    - Those GameObjects all have Components on them (at a minimum a Transform, maybe more)
    - Some of those other Components might be your MonoBehaviors
    - Some of those MonoBehaviours might have public or otherwise serializable variables.

    So... which part of the above isn't working?

    Or perhaps stated another way, ALL the above should be working... which one are?
     
  3. moneylife

    moneylife

    Joined:
    Mar 21, 2021
    Posts:
    10

    The component is a monobehaviour.

    I try to make a public property as a test. In this example (I've tried several) I try making a public value for the MaxSpeed. Ie...

    public class PlayerMovement : Monobehaviour{

    public float MaxSpeed;

    public void Start(){
    Debug.Log("player movement starts");

    }

    }



    The public variable does not appear as an option in Inspector. Also the debig log doesn't show.

    It references the empty version of the script. If I make changes and do that dumb.cs trick it will work. But subsequent changes are ignored
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    It sounds like you have errors in your scripts somewhere. Check your console.
     
  5. moneylife

    moneylife

    Joined:
    Mar 21, 2021
    Posts:
    10
    Thanks and I appreciate the help. But I have read the output logs and as I say it is all a default new project. The only thing I add is the public variable and or the debug line.

    There are no errors in the script i have made absolutely sure. Also like I say if I add a random new script to the same GameObject all the changes then pull through and populate in the inspector and also work correctly. Subsequent changes are ignored by unity until I do the same voodoo with the adding new script.

    When I'm home in hour or so I'll record short video yo explain it
     
    Last edited: Mar 21, 2021
  6. moneylife

    moneylife

    Joined:
    Mar 21, 2021
    Posts:
    10
    UPDATE: I have found that if I click "Assets>Refresh" after I make script changes it will work fine. But i have to click that every time.