- Home /
Can Scriptable Object be use for this?
Hi, let say that there is a Character.
The character has a Component A, with member variable a and b.
Initially, these variables are initialized inside the components.
However, as more character got added, the variables are supposed to be the same for all characters. As such, the variables got refactor to a reference objects instead.
Instead of making a GameObject, thus having a need to brought it across scenes, Is it possible to store the variables inside an Object that will be reference across all scenes?
Also, the variables must be able to get edited via Window Editor.
//////// Edit, summarize rephrase the Question
How do I create a Scriptable Object? How do I edit it via editor? and how do I reference the variable inside it from a component?
//////Add one more question,
With ScriptableObject, If the variable got edited during runtime, will the change be permanent? Or will it got reset after Game Restart?
For example, there is weapon with ATK 100, then it got upgraded to ATK110, in this case I want the change to be permanent.
If it will get reset, is it possible to make it permanent?
You can always use AddComponent to attach scripts to new gameObjects
Answer by Xtro · Jan 28, 2014 at 04:44 PM
Definitely you can use ScriptableObject for this purpose.
You have to do three things.
1) Implement a class from ScriptableObject and put your variables in it (public)
2) Create an instance of the class in the project structure and fill the values in it.
3) Reference to that object where ever you need it.
Example of implementing the class:
public class ExtraProjectSettings : ScriptableObject
{
public string WalkableTag = "Walkable";
public string CameraZoneTag = "Camera Zone";
public ParticleSystem TouchCircle;
public QualityLevel[] QualitySettings;
}
Please refer here about how to create an instance of your scriptableobject http://wiki.unity3d.com/index.php?title=CreateScriptableObjectAsset
Thank you Xtro, this is exactly what I needed!
I've also edit the main question and asked an extended question.
Answer by ZebraJoe · Jan 28, 2014 at 05:43 PM
It sounds like you might want to make a "Game Manger Script" that your other objects or charters can reference. You could then add a :
DontDestroyOnLoad (this);
In the Update of the Game Manger Script so that the variables within that script will remain constant.
Your answer
Follow this Question
Related Questions
Change values of variables in System.Serializable 1 Answer
Serialize a list of scriptable objects to Json 0 Answers
Make the same serialized class as a ScriptableObject? 1 Answer
Cannot see serialized object's fields in Inspector 1 Answer
[SOLVED] How do I change the values of an HDRP Volume Profile at Runtime? 1 Answer