[SOLVED] [Question] Issues with Prefabs and Unity 2019.1

Hi,
I know that this course has been recently remastered for Unity 2018.2, so I’m sorry if this may sound a little bit off-topic. I’ve already posted the same question on the Udemy Q&A Section but maybe here it’s more appropriate.

Currently I’m at lesson #69, and I’m faced with a little bit of differences between in what I see on my editor against the lecture: I see that in my Hierarchy the Game Canvas is blue as intended (since it’s a Prefab), but the TMPro text that I’ve added now doesn’t seem quite right.

Hierarchy

This creates some issues with the Game Status Prefab, in which apparently I can drag TMPro Text in the serialized field

Game%20Status%20Inspector

BUT, this does count as a manual change in the particular instance I’m working on (i.e. the Game Status in Level 1), and I can’t seem to apply it to the Prefab

This causes the game to freeze whenever I reach Level 2, in which I didn’t manually set the TMPro Text Reference in the instance of Game Status.

Obviously I can simply work around the problem by retrieving the reference of the TMPro Text in the Start Method through FindObjectOfType<>, but I wanted to know… What am I missing / not understanding?

Thanks for your attention and sorry for the wall of text, I hope I explained the question correctly and didn’t go too much off-topic.

Willy

Hi Willy,

I’m not exactly sure what you did. According to your Hierarchy, you seem to use Unity 2018.3+ or even 2019. In Unity 2018.3, a new prefab system was implemented.

Game objects in your Hierarchy get destroyed and created during runtime. For this reason, they cannot be referenced in a component of a prefab.

Your second screenshot shows the Game Status prefab. It does not have any children with a TextMeshProUGUI component attached. Did you try to attach a TMP component from your Hierarchy to the field? If so, you found the problem.

Is the GameStatus game object persistent? And is the text box supposed to be persistent, too? If so, you could add a child to the game object with the TMP component attached. Then you can drag the child into the field. Click on “Overrides” > “Apply All” to prefab the entire Game Status game object including the new child. This works thanks to the new prefab system.

I hope this helped. If not, please let me know what you are trying to achieve and what is not working yet.

1 Like

Hi Nina,
thanks for your reply. Actually, I found out that in the next couple of lectures Rick actually does what you suggest, i.e. making the whole Game Canvas a child of the Game Status Prefab. In that way the TMPro Text can be assigned in the Game Status script component of the Game Status Prefab.

Actually, I’ve also considered that trying to bind (in my Game Status Script) a reference of a different Prefab outside the scope of the one I’m working in didn’t quite make sense, because as you say (and as Rick mentioned in his lecture, too) it would link to something that is specific of the current scene, hence it cannot be made as a Prefab “attribute”.

Thanks for your help and sorry if my reply sounds a bit messy (I kinda struggle a bit when trying to explain myself in english for something rather complicated).

Willy

Don’t worry. I understood what you meant, and I’m glad you were able to fix your problem. :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms