Connect GameObject to a Different Prefab Variant

I have a set of prefab variants that are identical apart from the MeshFilter’s mesh, and I’d like to update my custom inspector so I can quickly cycle through the different meshes without having to destroy and re-instantiate the GameObject. What I’m currently doing is just looking at the MeshFilter and replacing it accordingly, but in the future, it might not just be one mesh but multiple GameObjects with additional meshes.

I realize that it’s a very specific use case, because in case a variant has additional data, that data would be destroyed when re-basing it on a different prefab. Technically, it would “just” be 1) diffing the GameObject’s data with the prefab’s, 2) switching the prefab reference, and 3) re-applying the diff.

Is there any way to do that?

Unfortunately that is not the use case for prefab variants and I don’t think that will ever be added because they aren’t ment to store data in that way (child inherits from parent, but knows nothing about sister variants. - gets way to complicated)

But this is a great use case for scriptable objects!

You can store the mesh filter in SO’s and then reference the specific ones you would like through the inspector. Makes it really easy to reference different data.

Hope this suggestion helps!

Yeah, the editor to support dealing with sister variants would be surprising indeed. I was more wondering whether there were APIs I could use to handle prefab references and diff and apply data.

Thanks for the SO tip, I’ll keep that in mind next time I touch that code. However, putting all meshes into an SO means that all the meshes always get bundled, shipped and loaded with the game, no?

Unless you use something like Addressables or Asset Bundles, yes each scriptable object with mesh data in it will get shipped with that mesh data. You could organize them out and keep them from being built with the game using those.

I imagine you are worrying about space then if you won’t want them all to get shipped, so your best bet is to use some kind of management tool like asset bundles to prevent certain meshes (depending on how your game handles them) from making it to release.