- Home /
Is there a way to Undo.RecordObject on a System.Object?
I have a Usable MonoBehaviour, that has a list of UsageEntry which is a Serializable regular C# class. 
 [System.Serializable]
 public class UsageEntry
 {
     [SerializeField] private string scene;
     [SerializeField] private List<string> triggers = new List<string>();
     public string Scene { get { return scene; } set { scene = value; } }
     public List<string> Triggers { get { return triggers; } }
 }
There are places in my editor code, where I make changes to the entries, mainly add/remove from the string list of triggers. I want the undo system to be able to revert those changes.
Undo.RecordObject take a UE.Object so I can't pass it the entry I'm modifying.
Also, it seems that it won't snap back if I pass it the Usable component instead, i.e.
     Undo.RecordObject(usableItem, "Updating item's trigger name");
     usableItem.UpdateTriggerName(previousName, currentName);
     Utils.UpdatePrefab(usableItem.gameObject);
Any ideas? (other than to make my UsageEntry class a ScriptableObject)
Thanks!
You know you didn't want to hear about ScriptableObjects, but this seems like a textbook case for using ScriptableObjects; you have data that is related to the scene, but doesn't really make for a GameObject.
well, the data in this case (the Usable component) will be attached to an Item GO, which in some cases it's in a scene, while in others it lives in a prefab, if it's the latter case, I would then have to create asset files for the SOs, and do all the manual setups to get a SO to work properly.
And TBH, it's just too trivial what I'm doing to be a SO, I mean, it's just an entry with 2 references, (it's so light that it's even qualified to be a struct...) - why go through the overhead of dealing with SOs for something that small?
Answer by pafla · Mar 01, 2014 at 10:15 AM
Strange, i did almost exactly the same just now - it worked perfectly... Maybe it's the way you store the UsageEntries in your component class. Or it is because I made all data public.
EDIT: Works fine with [SerializedField] too, so I guess the problem lies within Usable.
You are correct. Not sure why it didn't work, but maybe because I was handling the updating in the Usable $$anonymous$$B itself, and not the UsableEditor, now that I moved it there it works.
I might make a custom undoing system for System.Object, I'll post when I do. 
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                