Hello, I’m am trying to think of how to go about scripting something that checks if a object is a duplicate in the FBX on import, and if so, it uses the original mesh instead of being its own thing after import. The reason behind this, is having tons modular pieces and wanting to set it all up in modeling program, without having to recreate everything in Unity, and keeping the memory footprint the same as if I had.
I am thinking maybe I should think of my own naming convention such as thisMesh, thisMesh_isACopy0, thisMesh_isACopy1, etc to search for that string of _isACopy, and if it is not null, reference it back to the original mesh somehow. Unless FBX already identifies duplicates somehow. Or just replace it with original at the copies position. And at the end delete all duplicates from project folder, so that they don’t even take up build memory.
Please note I am not talking about instances. But I could swap things out for instances if need be. Duplicates could be tricky if a mesh is accidentally altered, It is not reflected in the other models. So things could get funky in that way. What do you guys think? I’d really hate to recreate my scene in Unity. I’d rather recreate it 10 times in modeling program (lol).
You’ll either need some custom exporter and importer scripts, or you’ll need to go with a strategy like the one you mentioned where you somehow mark the duplicates.
I’m not sure I get what you’re after with regard to instances. Do you want the objects to all use the same data or not? If they do then they’re instances and modifying any will modify all, because the referenced data will be changed. If they don’t then changes to one won’t change others as each will have its own data (which I’m pretty sure is how it works as it is).
Well, I’m going to be reusing the same mesh over and over, and then changing their materials to be different for some of them during runtime. Since I am doing this through a script, Im not sure if it would create a new set of data or what. What I’m using are modular pieces, but some of the time I need different material assigned by code. But even if assigning unique materials creates its own data for the mesh, I would still save memory in load up I think. So Im not sure if assigning different materials and variables in script (at runtime) would break instances or not, since I am not telling each to be different, but I give them the option to be different in code.
I guess I could instance the meshes but not the gameobjects as a whole(with scripts etc)? And do duplicates of the actual gameobjects. Im not really sure though.