- Home /
Make a instance of a script passed with prefab
Hello, the title says it all. I have a invenotry system, pretty straightforward - slots that hold item. This is how it looks like.
I just assign the starting items with prefabs, that are just an empty object, which contains the WeaponItem class and has already predefined values. But some of those are runtime - such as currentBullets currentMagazines or isReloading and when they change, they change it on the prefab and so that for example all the MP40's affect all the other MP40's in the level.
How could I go about making each WeaponItem it's own instance / severing it's connection to the prefab, so it does not affect the prefab iself? This is what I have tried so far
Thanks for reading!
O$$anonymous$$, the final solution was to make the items scriptable objects. Altough it is not recommended, I have to instantiate them due to the problem mentioned above, they actually work without creating object in game.
Answer by prof · Nov 17, 2019 at 08:47 PM
If you don't need object to be in scene, use ScriptableObject instead. And yes, you need to make new instance or copy values manually if you're going to change data, so original stays same.
Also, you really should break up static and dynamic data. Put your data that contains settings (that will not change during runtime) in separate class/struct
Yes, creating scriptableObject and instantiating that finally worked, thank you! And for the static and dynamic data, I think of moving the static data into the WeaponReferenceBase, which already contains weaponID, sound and also references such as the weapon model in hand to turn off when switching weapons etc. Thanks for the advice!
Your answer
Follow this Question
Related Questions
How to implement pickups that can go in a inventory 3 Answers
Text RPG inventory 1 Answer
Populate inventory with item icons 1 Answer
JavaScript Grid Array Size 0 Answers
Inventory Help. 1 Answer