- Home /
Find Source of Prefab Instance in Editor?
Hi All,
I'm currently trying to implement some editor functionality for level creation. The intent is to create sections of the level using Prefabs of environmental objects, etc. When these sections are done, export them out into a scriptable object recording the basic transforms data of said environmental Prefab instances.
After which, I need to recreate the level using those scriptable objects data. As such, my current thought is I need the ability to know what Prefabs to spawn back out. Is there any way to find out the source of Prefab Instances in the editor?
Side Note: You might ask why bother with scriptable objects in the first place? Why not just Prefab the whole section? I might be wrong here... But I was hoping theoretically, I could save filesize and processing by eliminating overheads involved with storing large Prefabs of many gameobjects.
Cheers
Answer by FlaSh-G · Apr 03, 2020 at 01:25 AM
I think you're looking for https://docs.unity3d.com/ScriptReference/PrefabUtility.GetPrefabInstanceHandle.html
Edit: Nah, apparently more like
https://docs.unity3d.com/ScriptReference/PrefabUtility.GetCorrespondingObjectFromSource.html
https://docs.unity3d.com/ScriptReference/PrefabUtility.GetCorrespondingObjectFromOriginalSource.html
Hey @FlaSh-G, thanks for replying. I've actually tried using that, and it only returns the outermost gameobject of that prefab instance. I'm looking for a reference to the Prefab source reference, not the clones or instances of it.
Dang, you're right. I misunderstood the description in the scripting reference.
After another search, I think you need one of these:
https://docs.unity3d.com/ScriptReference/PrefabUtility.GetCorrespondingObjectFromSource.html
https://docs.unity3d.com/ScriptReference/PrefabUtility.GetCorrespondingObjectFromOriginalSource.html
Hey mate, thanks! That was indeed what I was looking for. I must have missed it when looking through the docs! $$anonymous$$y glasses need glasses :) Thanks again!
Your answer
Follow this Question
Related Questions
Prevent changes in ScriptableObject type Asset in Editor. Dont save it. 0 Answers
Character Selection 0 Answers
Link GUIText to a prefab? 2 Answers
Not sure how to change color of individual prefab instance after it was touched 0 Answers
Create script from template, then create .asset file from new script 1 Answer