- Home /
Change Prefab 3D Model at runtime
Imagine you have a generic cube prefab with some scripts on it. Then you have 3 different 3D Models or "appearances". Is it possible to choose one of those models at runtime and assign its shape and appearance to my generic cube? Everything else except of the look(and shape) should be the same after the assignment. Is something like this possible and fast enough? Or should I reconsider my approach here?
Answer by robertbu · Oct 16, 2013 at 09:15 AM
In order to get the shape, you can swap out the mesh:
GetComponent(MeshFilter).mesh = anotherMesh;
It is plenty fast enough, but it is not without its weaknesses. Depending your your use, you may have to swap out the material as well. And if you are using a collider, you likely have to swap out the sharedMesh of the collider. An alternate approach is to have an empty game object as a parent and have all three "looks" as child game objects. You then enable and disable the game object as needed.
Your answer
![](https://koobas.hobune.stream/wayback/20220613120025im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
rotation problem 1 Answer
NullReferenceException on AudioSource in prefab 1 Answer
Power Meter? 0 Answers
How can I instantiate more prefabs as the score increases? 2 Answers
failed to initialize graphics 0 Answers