I’m working on an architechural visualization type project and using instantiate in an editor script to populate the world with objects exported from my CAD model, (wrote export script for CAD).
The majority of my “game” world is instantiated this way via this scripting.
When I’m instantiating prefabs, the instances don’t seem to be updating when I change the original prefab.
I am lead to believe instantiate is doing the same thing as dragging the prefab manually in the editor, but when it happens in the script, the editor doesn’t know to maintain the link between the instance and the original prefab.
I’d really like changes to the prefab to propagate down to the instances.
Particular issue right now is tweaking LOD distances. When I change the prefab I have to re-instantiate everything to check settings, delete them all, adjust prefab, re-instantiate etc. It’s taking me way too long to fine-tune this stuff.
Is this all in editor scripts, with prefabs instantiated at editor-time? If so, maybe try UnityEditor.PrefabUtility.InstantiatePrefab(). As described in the docs, “This is similar to Instantiate but creates a prefab connection to the prefab.”
This smells like it’s definitely what I need. Sorry, not trying to be dense but I’m not a programmer and the structure looks different to me. Struggling with how to implement this, can’t seem to find a code snippet that makes sense to me. Basically need to replace a typical Instantiate. When I try and use the code in the docs it just turns red and barfs everywhere. I have included “using UnityEditor;”
var newBlock = (GameObject)Instantiate(ObjectToInstance, matrix.GetRow(3), Quaternion.LookRotation(matrix.GetColumn(1), matrix.GetColumn(2)));
The transform matrix it’s using is coming from Rhinoceros. Looks like I’ll have to reposition and reorient the prefab afterwards in this case but I think I can handle that.