Hi everyone,
I have a script that has a custom class as a field, such as this:
public class MyClass : Monobehaviour{
public GameObject prefab; // a prefab that has a MyClass component
public SomeClass someClass;
}
public class SomeClass{
public int x;
public SomeClass(int _x){
x = _x;
}
}
What I’m trying to do is instantiate gameobjects with a MyClass component attached to them via a custom inspector for MyClass. Specifically, I want to set the someClass field to a specific value. Im currently trying it as follows:
[CustomEditor (typeof(MyClass))]
public class MyClassEditor : Editor{
public override void OnInspectorGUI() {
DrawDefaultInspector();
MyClass mc = (MyClass) target;
if(GUILayout.Button("button")) {
GameObject go = (GameObject) Instantiate(mc.prefabToInstantiate);
go.GetComponent<MyClass>().someClass.x = 1;
}
}
}
This does indeed instantiate the desired object and sets x to 1. However, as soon as I start the game, the field x is not set to 1 anymore. Is there any way to make this value persistent, even when entering play mode?
Cheers.