- Home /
how to save a prefab of a object during play mode
so here it is i have two scenes.. one is the playing scene were the game is played. and the second scene is were the player can customized guns by instantiating things onto the gun
so the question becomes how to save a prefab of the gun and save it. is this possible to do?
Can you be more detailed? what do you mean by instantiating things onto the gun? are you picking up stuff in the level and using these stuff you can customize your weapon?
I have a Gun GameObject That I Instantiate a object and then $$anonymous$$ake it a Child of the Gun Object. so what i need to do is to save it that somehow so i can be able to access it whenever i need
Answer by Cherno · Jun 05, 2015 at 08:14 PM
Creating prefabs during runtime is only possible if running the game from within the Unity Editor. If you need to create prefabs during runtime of an actual build, you have to create a workaround. For example, you could always use the same prefab which has just the most basic components (MeshRenderer, MeshFilter) and save the information that fills these components; Upon instatiation the prefab, you then use this information to assign the right mesh, materials, children and so on.
It depends on what you are trying to do, ther can be nore single tutorial that caters to every game's needs. Just think about what you are trying to do, what kind of data needs to be saved and loaded, and go from there.
Here is a short tutorial on saving & loading data which you can use as a base. The "testString" variable in the "Game" class could be the name of a mesh to use, for example, which you would then load via Resources.Load, using the string as the mesh name.
If there is too much information to save you could try looking into serialization.
Answer by starikcetin · Jun 06, 2015 at 12:26 PM
I think the thing you are trying to do is, storing a gameobject and using it later. You don't need to use prefabs for this.
You can just declare a public static gameobject and store your gameobject on it, then whenever you need it Instantiate it from your public static variable.
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Making an FPS arcade game. 0 Answers
Having trouble increasing the spawning speed of explosions 0 Answers
HOw to make a custom mesh collider 1 Answer