Adding new 3D objects during runtime/ after build
Hello
I have bunch of 3D models that are made into prefabs by hand, so that algorithm could automatically place them into realistic positions (on ground, next to wall, on wall etc). And I was thinking how could I give user a way to add these objects on their own if they have only the built version. If I'm right, it can be done using AssetBundle. But I am now to the whole Unity so I am not sure.
And if I will be able to use AssetBundle for that, can I let user to create the .prefab files themselves and then add the to a right directory so that my program could automatically import from there?
Or do I have to automate .prefab creation so that the user has to only place a desired 3D model in the right folder
Answer by RyanAchtenSoma · Mar 24, 2016 at 10:49 PM
Pretty sure you can't create prefabs at runtime due to their creation relying on editor functionality (not included in builds). You can however import the mesh of files at runtime in the form of .fbx or .obj files.
Not sure about using Asset Bundles, but a quick way of parsing models at runtime that I use is via the ObjReader which is super quick due to running off an external .dll (Unity's built in .obj parser is much too slow for my taste). Pretty sure ObjReader can parse multiple objects at once so you could definitely create a system like you describe above.
@RyanAchtenSoma, thank you for your reply.
Prefab allows me to create a template of an item. And later use that template to generate random number of instances of it and they all behave the same (lets say... have tags "on wall" so all of them will be generated on walls).
If I understand ObjReader description right. It imports .fbx files into game and makes them into GameObjects. Then how can I add these same prefab tags to these new GameObjects?
Yeah as mentioned above, pretty sure creating prefabs isn't functionality supported by builds as it is reliant on the the editor environment.
You could store the 'tag' information you mention in an xml schema of some description along with the model location on you local system, texture location, transform coordinates etc etc to sort of replicate the role of a prefab (obviously this won't be optimised the way a prefab is though). To add a 'tag' in the Unity sense you can just go gameObject.tag = "tagName"
Your answer
Follow this Question
Related Questions
Importing new 3D models without editor 0 Answers
Change object Color during runtime 0 Answers
Help (reloading a level) 0 Answers
Issues with video player coroutine 2 Answers
reverberation time and microphone dB value visualisation 0 Answers