Hello, I’m having a silly error. I have a string variable in my code to reference a button’s string, in this case, I was testing with “Jump”. The error is that if this variable is public or has the [SerializeField] attribute, it becomes empty (“”) after the first iteration of the update. This is happening in version 2022.3 and “Visual 2022”. I don’t know where to report it because it’s frustrating.
I’m attaching two images. One shows the state during the first iteration that enters the update, and the second image is from the second iteration.
P.S.: I made sure that nothing is modifying that variable (at least not in my code). I’m not sure if internal Unity editor processes are doing something strange that I’m not aware of.
P.S.: I also tried closing and reopening Unity just in case, and the issue persisted.
P.S.: I’m also sure that the inspector field has “Jump” written in it, both in the instance and in the prefab, as it should be.
Throw a Debug.Log into Start that prints out the value and uses the second overload that takes in the object context too, so it pings the object when you click on the log entry. Ergo:
Debug.Log($"Button Code: {buttonCode}", this);
This should help you hunt down and errant components that don’t have this field assigned/filled out properly.
And change buttonCode accessibility from public to [SerializeField] private so that if any external script does access this field you will get a compile error. It‘s bad practice to have public fields to begin with (except data-only classes/structs).
Thank you very much, it was indeed a silly mistake. I had 2 MonoBehaviours in the prefab, one of which shouldn’t have been there, and I hadn’t noticed it. I relied on Visual Studio’s debug, thinking it was showing me the same component.