I’m not even sure what is going on here.
You’re marking the thruster field for serialization so it shows in the editor, and gets serialized.
Then you’re new-ing a fresh non-MonoBehaviour thruster script up at Awake
As part of that you expect it to be the same one and have the ParticleSystem you might have set in the inspector.
I assure you the class you create with a new won’t have that ParticleSystem defined. I also have no idea where you intend to set that. It won’t be in the inspector because obviously when you run, Awake() will happily wipe it out with the new
call.
Serialized properties in Unity are initialized as a cascade of possible values, each subsequent value (if present) overwriting the previous value:
-
what the class constructor makes (either default(T) or else field initializers)
-
what is saved with the prefab
-
what is saved with the prefab override(s)/variant(s)
-
what is saved in the scene and not applied to the prefab
-
what is changed in Awake(), Start(), or even later etc.
Make sure you only initialize things at ONE of the above levels, or if necessary, at levels that you specifically understand in your use case. Otherwise errors will seem very mysterious.
Field initializers versus using Reset() function and Unity serialization:
This might also be useful to you:
Here is some timing diagram help: