- Home /
How to modify prefab permanently via script.
Hi,
I'm currently working on a project where I need to improve/magnify a 3D model built via SketchUp.
One of the way to improve it, is to add animation on some object. For Instance, I created some animation so the doors now open when the Player come near by.
Right now, I have a small script that allow me to replace all the "standard door" by my Animated_Door at RUNTIME ( which works well and is quite... ugly ? ).
GameObject[] allObjects = GameObject.FindGameObjectsWithTag("Untagged");
for(int i = 0; i<(allObjects.Length); i++){
if (allObjects[i].name.Contains("door") == true)
{
GameObject frontDoor = Instantiate((GameObject)Resources.Load("FrontDoor"));
frontDoor.transform.SetPositionAndRotation(allObjects[i].transform.position, allObjects[i].transform.rotation);
DestroyObject(allObjects[i]);
}
}
So here's my question. Is there any way to directly modify the prefab I receive( the only thing I know about the prefab I receive is its name ) via a script that would add the animation component in editor where I can save the change. A script that I could run each time I receive a new model so I don't have to change it manually again & again.
I found some things about UnityEditor & PrefabUtility.ReplacePrefab but I'm not sure it will work like intended ( Never used either and I can't find a good (not deprecated) tutorial).
Thanks for reading so far.
Your answer
Follow this Question
Related Questions
Mark gameobject field as changed from prefab 2 Answers
Automatically update prefab instance 1 Answer
How to save generated objects? 2 Answers