- Home /
Creating an instance of a ScriptableObject, that will not change the base asset.
Title says it all, but For Example:
I have a ScriptableObject "SwordA". Whenever I find the Sword "SwordA", it's base and default values would be equal to the ScriptableObject "SwordA"'s values. However, if I upgrade my newfound sword's sharpness and change values of ScriptableObject "SwordA"' in code, it changes them to the asset too. How can I create an instance of the ScriptableObject such that changing for one sword doesn't change the base values for all new Sword "SwordA"'s I find later in the game? Can I do it without creating a private float and setting sharpness equal to it?
Answer by Glurth · Feb 02, 2019 at 04:21 PM
If you don't want to keep each INSTANCE of "Sword" stored as a scriptable object, you will need to save those values yourself, somehow.
I would suggest this be done by storing whatever "contains" the sword instances (e.g. player, map, npc, whatever), as a scriptable object, that has a (serializable) list of "Sword" objects, each with its own individual values.
With this method, you would create an instance of your SwordA (think of it as a prefab), then add this new instance to your player/map container object, and apply all your "bonuses". Then simply save the player/map itself as an asset, rather than saving the sword instance itself.
Answer by hameed-ullah-jan · Feb 02, 2019 at 07:13 AM
You can take copies of the scriptable objects under the project view, and set different properties for each sword (just like you do in prefabs). then for each sword use its corresponding scriptable object.
That is being done, but if I upgrade a sword, the base scriptable object changes. I dont want that as if I have 5 "sworda" objects, then upgrading 1 will upgrade all of them. I dont want to have a scriptableobject for each and every sword
Your answer
Follow this Question
Related Questions
Is it possible to write a function in the backend of an editor script for a scriptableObject? 0 Answers
Set default length for an array of elements of a custom class in inspector 0 Answers
Confused about custom GameObjects,Custom GameObject confusion 0 Answers
NullReferenceException: but I have checked that there is a object and have a if(obj != null) before 0 Answers
Multiple Cars not working 1 Answer