Confused about Unity prefabs to Babylonjs instances

I have a scene in Unity which has over 900 objects. They are all from prefabs. I was hoping to be able to export using the Babylon.js exporter and have them converted to instances. This doesn’t work automatically. I’ve checked documentation and forum posts and apparently you can mark objects as “Babylon prefabs” using layers. This will mark it as a prefab in the resulting .babylon file but I’m not sure how to then convert that into an actual Babylon.js instance.

Are there any example videos or demos of this working?

I did some searching and it looks like the original developer of the Unity exporter has gone AWOL.

3 years ago I made changes to the Unity exporter to handle prefabs and instances and added them to the main repo. Sometime last year all these changes were wiped over completely with new code. Anyway, my code is still available which you can find here Babylon.js/Exporters/Unity 5 at master · punkoffice/Babylon.js · GitHub

This is a few years old, before there was any armature or terrain parsing so DO NOT use if you need those features. This will convert prefabs to instances straight in the resulting .babylon file. No other conversions or coding required.

Yes I don’t know where mackey goes.
This is also one of the main reason why I did not want to integrate his toolkit in the main core repo. Maintenaince over time is at least as much important as the original code itself and being able to commit yourself to support your code forever is not easy

My toolkit marks meshes as PREFAB. This basically serializes the mesh with mesh.enabled = false

Then you can use the Scene Manager manager.instantiatePrefab function … this basically CLONES the mesh hierarchy…

Dunno what you mean by instance… but the toolkit does support creating actual Shared Mesh Instances by calling manager,getPrefabMesh… to get a reference to the original disabled mesh… from there to make a INSTANCE… use the Babylon Mesh.createInstance to create a standard shared mesh instance instead of a full CLONE using manager.instantiatePrefab

FYI… the original exporter before I took over the toolkit is still there… I think it’s under a folder called Deprecated. You can always fallback on this version to get the code the original exporter developers created

I still use Babylon (just been leaning more towards GLTF as file format).

I couldn’t get any coding help to really create the game mechanics I invisioned for the toolkit … so my First toolkit kinda got stuck in limbo.

But again… if anybody needs help that I can give info on… I will. Like I have always done. You wanna rape and pillage parts of the toolkit for own projects or start a new one entirely… I would glad to help.

If anyone want to help me make better toolkit… I would love any help from you as well

Thanks @MackeyK24 for the info.

I contributed to the Unity Exporter over 3 years ago then the repo got completely wiped over so my changes aren’t even in the “Deprecated” section, however, my repo fork is still up on GIThub so I just resorted to using that code.

The way my code dealt with prefabs was to make one of the prefab instances the actual mesh and all other prefab instances Babylon.js instances of that mesh. It would create the “instances” JSON field right in the .babylon file so it would all show up when the scene is loaded with no extra coding required. If I have time I’ll try and incorporate it into your code.

This is the code I had for parsing instances. Its not perfect. There can be some issues if its a child (I just have to unparent the child) but I will sort those issues out in time.

The main reason i dont use the JSON instance fields.

I want the ORIGINAL mesh hierarchy to serve as the SOURCE. Then i can create a CLONED hierarchy to create prefabbed copies. NOT INSTANCES… Since instances can only change basically position… Not materials and skeletons. One of the main uses is the a PLAYER character with fully animated skeletons. Using my system. I can create a character, dress him up, bake animations etc…

then using code i can simply say: manager.instaniatePrefab(“Player”) to create one or more TOTALLY CLONED prefabs with attached scripts. I do this alot in my games… Also if i need an actual SHARED INSTANCE i can get that original prefab mesh and create instance.

Making EVERYTHING on the prefab layer a actual MESH INSTANCE wont really workout… Some things it would, but not a good solution for general workflow you would use when making UNITY STYLE games using the toolkit as your main IDE

No worries. I figured you had good reasons for the way you structured it.

My needs are pretty specific for the project I’m working on. I just need to be able to export my scene from Unity then load it in Babylon with the smallest filesize and least draw calls. These Unity scenes won’t have armatures or particles.

So its all good. I got what I need. Everyone else can use the official Unity exporter

Glad to see you back @MackeyK24!!