1

Newly added field in ScriptableObject class not being put into assets of its type. Is this something todo with how Scriptable Objects work? Is there a way to update a scriptable object asset without losing existing info in already populated fields?

My ScriptableObject class has a bunch of strings for animation:

public class SO_AnimStringNames : ScriptableObject {
public string FirstAnim;
public string SecondAnim;
public string ThirdAnim;
}

I've created a ScriptableObject asset via this class, and added names to the strings, and used it as data within another object type, that uses those strings.

Just now, added a fourth string to the ScriptableObject class, so now it looks like this:

public class SO_AnimStringNames : ScriptableObject {
public string FirstAnim;
public string SecondAnim;
public string ThirdAnim;
public string FourthAnim; // newly added field
}

but it's not seen/updated within the ScriptableObject asset, and there's no obvious way to update this asset.

Is this a limitation of ScriptableObjects, or is something else wrong?

Confused
  • 6,048
  • 6
  • 34
  • 75
  • 1
    Should happen ... Any compiler errors that would hinder Unity from recompilation? How exactly did you create the asset? (I suppose this is not the complete code?) – derHugo Dec 21 '20 at 22:48
  • This was the problem! I'd added something in another file, a new abstract method, and hadn't cascaded down all the overrides needed. Missed two, and didn't think anymore of it, whist doing other things. – Confused Dec 22 '20 at 21:38
  • Thank you, @derHugo, feel like a right muppet. – Confused Dec 22 '20 at 21:39

1 Answers1

2

I'm a bit confused with your issue here, so...

Option 1: I just tried what you did, but I added the CreateAssetMenu attribute on top of your class, someone mentioned you probably didn't share all of your code but in theory this is how it should be looking:

[CreateAssetMenu(fileName ="NewAnimStringNames",menuName ="Animation Names")]
public class SO_AnimStringNames : ScriptableObject
{
    // made an instance with these three first
    public string FirstAnim;
    public string SecondAnim;
    public string ThirdAnim;
    // then added the fourth variable, the instance I created previously updates correctly 
    //and keeps the values I set on the other three
    public string FourthAnim;
}

Is that how your ScriptableObject actually looks and you're creating them from Assets/Create menu or with right click on your assets plus create menu?

Option 2: They also mentioned that maybe you have another issue that is not allowing Unity to recompile leading to your ScriptableObject updating itself with the new field? Please check the console for any other issues.

Jls
  • 74
  • 5