- Home /
The question is answered, right answer was accepted
Cannot apply certain elements in prefabs(GUI)?
Hello,
I have a character prefab and am trying to update it in the prefabs folder I have in my project window by pressing apply and/or dragging the character to replace the character prefab in the project view. Everything “applies” when I do that except for the GUI elements that were assigned.
For example, I have “hearts” gui as sprites for life in the top right of my screen and in the inspector I have slots for the hearts to be assigned. But when I do assign it then apply it and redrag out the prefab into the scene all the GUI elements are reset to null in the slots on the prefab. Is there a reason it’s doing this? Can I not do this?
Is it because I can't reference GUI elements in a prefab(even though the GUI is the same in each scene)? This is just a guess but I was wondering if it's right. If it is right can I just initiate it in the start function or will it be the same? I am using Daikon Forge GUI but I don't think that is the problem.
Thanks!
Answer by kannan21 · Mar 17, 2014 at 06:50 AM
Assigning it in start will solve the problem for sure. But you can assign GUI elements to a prefab. There should not be any problem in that.
Thank you for the reply, I just talked to someone about it and they said you can't assign GUI elements to a prefab but as you said assigning them in start will work. So I will mark this as the answer since it would have fixed it anyway. Thanks again!
The problem is that you can't reference anything from a scene inside a prefab. Objects in scenes aren't there all the time, only when the level is loaded. Prefabs on the other hand are assets which can be used everywhere. So it's impossible for a prefab to reference an instance inside a scene.
Also you said all scenes have the same objects. That would mean each scene has it's own set of objects. Just because every B$$anonymous$$W has s driverseat you can't reference one to get them all ;)
Yeah I can't believe I've never encountered this before, I have been working with Unity on and off for 2 years now too. I also can't believe how noobish my question was :)