- Home /
Refresh gameObject to original prefab, but it isn't visible
Hello, so I'm making a RPG-type game where the "battle system" takes place within a UI prefab. However, it loads in data on Start(), which might change between uses within the same scene, so I wanted to have the UI spawn in a new instance of the prefab in its place and then delete itself. However, when I go to enter a "battle" a second time, it never shows up but it still seems to be functioning in some capacity (given activity in the log). When I instantiate the second UI, do I need to alter it in some way to allow it to be seen, or is there some better way to do this?
EDIT: Here's what the original UI does when it's time to close:
g.battle = false;
g.pList [0].battleBox = Instantiate(battlePrefab);
g.pList [0].battleBox.SetActive (false);
Destroy (gameObject);
"g" is just a class for global variables, and pList is the list of party members (with index 0 being the main character), so it's basically replacing the old one (Which used to be in battleBox) with the new instantiated one, then setting the new one to be inactive until it's needed, then destroying the old one.
Do you delete your old UI before you spawn your new one? $$anonymous$$ake sure your new UI is within a Canvas, and that you have an EventSystem in the scene in order for the input to work on your UI.
Please show some code, the likelyhood is that you are editing the prefab at runtime OR replacing the prefab reference with your new instance or disabling it, then spawning in an already disabled version of the prefab.
Answer by Bluestone19 · Feb 23, 2019 at 05:21 PM
After doing a bunch of messing around with it, I've figured out that somehow the newly instantiated UI just doesn't exist at any point, as it doesn't show up in the hierarchy when I pause. Does deleting the object which instantiated it delete the new one? Or is deleting the only instance of the prefab in the scene somehow deleting the whole prefab (and thus all other instances, or stopping them from being instantiated)?
What are you instantiating? It sounds like you're instantiating an object from the scene hierarchy, which you should not do. You need to instantiate an object from your project folder.
So I have a prefab of the whole UI, but I want one instance of the prefab to exist from the start of the scene, and then for it to spawn in another one of the same prefab and then delete itself.