Unity Model and Prefab Replacement Tool
by Gabriel Sibley, Lead Developer
In this post, I’ll be writing about a typical problem with rigged models in unity and the tool we created to solve this problem. This tool has made our development process faster and easier and we are freely releasing it so that you can benefit as well.
What’s the problem, anyway?
You’re making a game in Unity, and you have some rigged models in it. But a model on it’s own doesn’t do much, so you’ve added behaviours and new GameObjects to the model’s hierarchy, for example particle systems or a connection point for a prop. These additions are built up over time, are added by different people, and are often buried deep in the model’s hierarchy because they need to move with particular bones.
Then, you find out you need to change the model for some reason. It needs a new mesh, or new bones. The old model hierarchy, with all of its organically grown additions, will no longer work. Porting all of the changes that were made to the old hierarchy to the new one requires painstaking effort. It’s time consuming and error-prone.
This has a variety of negative consequences. Once behaviours and effects get added to a model, the inertia of changing that model skyrockets. This can mean slower art iterations, a reluctance to experiment with (or even tweak!) character art, and less time spent on other features. It also means that changing a model can result in bugs it has no real business introducing, just due to things getting lost or broken during the changeover. If several model iterations happen before a bug is noticed, it can be a slog to figure out and restore the proper behaviour.
How we solved the Problem
In order to make this process of replacing a model faster and less error-prone, we created an editor tool, cunningly named the Model Replace Tool. The tool automates the bulk of the grunt work associated with the process by finding all of the additions to the old model and re-creating them on the new model.
Here’s what it looks like:
The Model Replace Tool does a few things. First, it makes a comparison between the current hierarchy and a baseline hierarchy to see what’s been added. Generally, the baseline used is just the asset that your 3d modelling program kicks out, but if you wanted to use a special template asset you could do that too. The tool gives you a tree view of all of the additions it discovers.
Second, the tool lets you copy all of the additions over to a new hierarchy in one go (or selectively omit them). Each addition to be copied must be assigned a target in the destination hierarchy. To make things go faster, when you assign a target for a node the tool will look at object names to guess targets in the destination for all of its descendants. This can save a lot of time when the hierarchy has not substantially changed during a model update.
After all the additions are copied over, any custom postprocessing functions get run. Any component that gets copied and has functions marked with a particular attribute will have those functions invoked. So if there are some special setup tasks that need to be done every time the model is changed, you can automate that process to make sure it gets done the same way every time.
Finally, the tool scans for any remaining serialized references from the new hierarchy to the old one. Commonly, these references can be automatically fixed to point to the corresponding object in the new hierarchy. Any references that the tool doesn’t fix get logged, so you get a list of what needs to be touched up manually.
The Model Replace Tool is available from our GitHub page.
Arcturus is a Virtual Reality studio creating original interactive narrative experiences. For more information Sign up to our newsletter.