- Home /
Prefabs Workflow - Changing models in a 3D app after they have been used in a prefab
Hi, I'd like to know what's the right workflow and how to use Prefabs for writing Unity games where its used meshes get updated by modelers (using Maya) while the game is developed in Unity.
I've got the following problem:
I build a model in Maya
I import the .mb file in Unity
I drag it from Project pane into Hierarchy pane
Create in the Project pane a Prefab
Drag the top level object from Hierarchy pane onto prefab in Project Pane
I (or any modeler) change the model in Maya and overwrite the model in the Asset folder
Now in the Project pane are two models: the one I originally imported and the prefab. After updating the model in Maya, the original model in the project pane changes (I can see the changes made to the model in the small preview window), but the prefab doesn't get updated, nor does the object in the Scene View (in the Hierarchy pane respectively).
How can we change geometries already in use by the Unity project afterwards?
cross reference http://answers.unity3d.com/questions/8838/how-can-i-keep-the-prefab-connection-when-re-expor.html Greetz, $$anonymous$$y.
Answer by duck · Apr 16, 2010 at 04:49 PM
I have come up against this problem, and I currently work around it (to a certain degree) this way, by adding an extra step:
Build Model in 3D app
Import the .mb / .max / .fbx file in Unity
Create a new empty gameobject in your hierarchy
Drag your imported model onto the empty gameobject (so you model is a child of it)
Create a new prefab in your project pane
Drag the top-level empty gameobject (which has your model as a child) onto the new prefab
Now, I find this method works for mesh changes to the existing objects, but it still doesn't pick up any changes in transforms to the existing objects, or any additional new objects added to the original file.
I know this doesn't seem like much of an improvement; it still requires a manual update if any models were moved or any new models were added. However, because your model is now a child within the prefab, it becomes a lot simpler to delete & re-add your model to the prefab.
Before, if you had made a prefab with your model as the root object (as opposed to an empty GO), you would probably have added components, scripts and adjusted settings, and from that position, it seems that there is no way to update the model without losing all these components and their settings. You simply have to delete and re-make the prefab.
Wheras now, because your model is a child within the prefab, you would add your components and scripts to the empty base GO, and this means you can preserve that whole part of the prefab while just deleting & re-adding the visible model part (you'd do this to an instance in the hierarchy, then choose "apply" to apply your changes to the prefab).
Hope this helps!
This is what we do too, and for the same reasons. You may need to modify some of your scripts if they are expecting certain components to be in the root object. For example, if your scripts do GetComponent for a mesh or animation, you'll need to update those to search child objects too. Typically just do that in Start() and keep a reference to them so the rest of the script can refer to the right one.
So there is no way to update a mesh in the Hierarchy pane, when a modeler changes position, scale etc. in $$anonymous$$aya? And adding submeshes, replacing meshes and making meshes more detailed (triangle count) doesn't work either? What about Color? In all these cases you have to delete the object from Hierarchy pane, reimport it, drag it from Project pane to Hierarchy pane again and add all scripts and components to its child objects (if they can't be moved to the parent node) and modify the scene hierarchy again as it has been before?
Hm, I don't get it. In the Unity Video tutorial No. 5 (see http://unity3d.com/support/documentation/video/5.html) the author applies a rigidbody and a collider to a game object without losing prefab link. That's why thereafter he can make changes to the model in Studio $$anonymous$$ax which are automatically applied to the unity scene on saving. If I try doing the same, Unity asks me if I really want to lose prefab...
Answer by gooncorp · Jun 30, 2012 at 05:26 PM
man do i really have to spend 3 hours doing this everytime my partner gives me an updated model? it takes over 3 hours for me to update the model if he adds for example gloves...
Answer by Bill 2 · Oct 08, 2010 at 11:01 AM
Here is what we are doing that seems to be working well and allows the 3d model to be updated and have prefabs that use it update as welll.
Import the model make an empty game object, call it "Global" and throw a script called "Global" on it that has something like
var myModel:GameObject;
Then click on Global in the heirarchy and drag the 3d object in the project panel into the myModel var in the inspector.
Then in any script on any prefab you can instantiate the 3d object in the start function
function Start(){ var model=GameObject.Find("Global").GetComponent(Global).myModel; var newModel=Instantiate(model,Vector3.zero,Quaternion.identity); newModel.name="CharacterObject"; newModel.transform.parent=transform; newModel.transform.localPosition=Vector3.zero;
}
Hope that helps
sweet stuff. I love it how the script file actually holds a higher class of functions. $$anonymous$$ooo Booo