- Home /
How to dereference multi-tired class?
I created a custom inspector that is used to add actions to a scriptable object file. Each action is a class with loads of data in it. Here is an example:
// Character Actions
[System.Serializable]
public class Actions
{
public string actionName = "";
public Character[] template = new Character[10];
public int[] arg_int = new int[15];
public float[] arg_float = new float[10];
public string[] arg_string = new string[10];
public bool[] arg_bool = new bool[10];
}
If I copy and paste an action in my custom inspector's list, this inserts a pointer to the original action. So if I make any changes to either action in the inspector, both actions are updated. I have found only two ways to dereference the pointer:
(a) test play the game. when I start/stop test play, the actions are no longer linked.
(b) assign every value manually to a copied action. This is an annoying amount of work. Here is an example:
public Actions CopyMembers (Actions pAction)
{
Actions newAction = new Actions();
newAction.actionName = pAction.actionName;
... continue steps for arrays and embedded classes...
return newAction;
}
The above code derefernces the pointers as long as I change every single value separately. If there is a class inside Action, I have to complete the same steps for every single value in every embedded class. It's insane!
Am I missing an easy way to dereference a pointer to a class that has multiple levels of data?
Your answer
Follow this Question
Related Questions
Custom Inspector doesn't show changes immediatley 2 Answers
Accessing subclass properties in inspector based on enum 1 Answer
Abstract classes in a ScriptableObject 1 Answer
Custom Inspector - break link between duplicate fields? 1 Answer
I neet to make like a Hyper Procedural Dynamic List on Unity 2 Answers