- Home /
Instantiating prefabs creates a clone, not instance of the prefab
I'm working on a custom solution for solving nested prefabs in a personal project. Right now, I'm trying to get a script to instantiate a prefab at runtime, update all of the nested prefabs withinin it, apply those changes, then remove it.
The problem is, when I instantiate the parent prefab, it has the word 'clone' next to it and doesn't seem to count as an actual instance of the prefab, just a unique game object based on the prefab. In other words, even if I made changes to it manually in the editor, there is no 'apply' button to apply changes to the original prefab - I'm talking about the parent, not the nested prefabs.
So if I instantiate a prefab through editor code like this:
GameObject currentTile = Instantiate(tile.gameObject);
Which is a game object with many nested prefabs, and then I make changes in the editor to currentTile, currentTile has no 'Apply' button to update it's original prefab.
Anyone experienced this and know why it's not counting as an instance of the prefab?
Answer by UnityCoach · Aug 04, 2017 at 11:25 AM
If you want to do this in the Editor and want it to be an "instance" of the Prefab, you need to use PrefabUtility.InstantiatePrefab. Note that at runtime, Prefabs don't exist, they're nothing but serialised GameObjects.
You are a legend! Yeah that worked! Solved it with:
GameObject currentTile = PrefabUtility.InstantiatePrefab(m_tiles[0].gameObject as GameObject) as GameObject;
Thank you!
I know this was half a decade ago but how exactly did you go from just the "tile" game object to going to an array of "m_tiles[0]?
Dude you have no clue the time I spent researching this :D thank you so much !
Your answer
Follow this Question
Related Questions
Prefabs spawn with wrong values 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Resources.load allways returns NULL but the Path seems to be correct 1 Answer