- Home /
Question by
syabhri · Feb 25, 2020 at 12:32 PM ·
scriptableobjectinstantiationclass instance
is class variable in a ScriptableObject automaticly Instantiated?
while I created an Instance of ScriptableObject with a class variable in it, in the inspector it shows the class variable as default instance of the class, do I still need to add a null checker before getting data from it?
[CreateAssetMenu(menuName = "VariableContainer/TimeContainer")]
public class TimeContainer : VariableContainer<TimeFormat>
{
public Action<TimeContainer> OnValueChanged = delegate { };
public override TimeFormat Value
{
set { this.value = value; OnValueChanged.Invoke(this); }
get { return value; }
}
public void Reset()
{
Value.Reset();
}
}
capture33.png
(11.5 kB)
Comment
I was just going to suggest that :P
Best Answer
Answer by xxmariofer · Feb 25, 2020 at 01:10 PM
if it gets serialize, you dont need to, similar to how when you mark a list public like
public List<string> example;//gets serialize in inspector
you dont need to initialize it
public List<string> example = new List<string>();
Your answer
![](https://koobas.hobune.stream/wayback/20220612223936im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Creating new scriptable objects at runtime 1 Answer
How to Instantiate a GameObject from a ScriptableObject piece of script? 0 Answers
Null Reference Error With Scriptable Objects 1 Answer
Manually Save/Load Unity Serialization Data 0 Answers
ScriptableObject problem and creating a new class instance 1 Answer