The order of serialize fields

Hi!
Why does this works (i.e., changes the text of the question while playing)-

[SerializeField] TextMeshProUGUI questionText;
[SerializeField] QuestionSO question;

and this -

[SerializeField] QuestionSO question;
[SerializeField] TextMeshProUGUI questionText;

doesn’t (fails to change the text of the question while playing) ?

Thanks.

1 Like

No idea. There is no reason I can see/think of that either wouldn’t work.

1 Like

Thanks.

1 Like

If you give more detail about what “doesn’t work” mean we could possibly figure out what the actual problem is

1 Like

With the following order-
[SerializeField] QuestionSO question;
[SerializeField] TextMeshProUGUI questionText;

After pressing play, the text of the question does not change from “Lorem Impsum…” to my original question.

With the opposite order-
[SerializeField] TextMeshProUGUI questionText;
[SerializeField] QuestionSO question;

After pressing play, the text of the question does change from “Lorem Impsum…” to my original question.

1 Like

This doesn’t make sense because the order in which variables are declared doesn’t usually matter unless one references the other which is not the case here. I will have to run some tests with this

1 Like

I am unable to reproduce this behaviour. The text is shown no matter which order I place the variables. Can you show this behaviour happening?

1 Like

I’m too far ahead now and cannot reproduce it. I guess it was something else that I missed.
Thanks for your help!

1 Like

Privacy & Terms