- Home /
Saving object like a prefab at runtime
Hi! I'm creating an editor where the player can put parts together to make a vehicle. I want to save it like a prefab so individual parts can be destroyed. I need to save it so the player can reuse or edit it at any time. I read that it's not possible to make a prefab at runtime so what other options are there? -Thanks
Answer by Cherno · May 03, 2015 at 01:55 PM
It's perfectly possible to create a prefab at runtime, but not if it's a stand-along build.
For a stand-alone build, you just need some sort iof identification system. Make all seperate parts prefabs and load them into a list or array, or dictionary. Your vehicle base gameobject then needs to hold a reference to the parts; strings so you can reference their name, for example. Once these references are filled, you just create the vehicle from the referenced parts as you normally would, with Instantiate(). Now you just need to save the class holding the references.
Your answer
Follow this Question
Related Questions
Saving gameobjects' properties for Dynamically growing prefabs 1 Answer
create prefab at runtime 0 Answers
Creating/Saving prefabs during runtime? 7 Answers
Avoid altering prefab at runtime 1 Answer
making prefabs at runtime? 2 Answers