Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
5
Question by vexe · Mar 01, 2014 at 08:02 AM · undounityengine.object

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!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jamora · Mar 01, 2014 at 08:50 AM 0
Share

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.

avatar image vexe · Mar 01, 2014 at 09:56 AM 0
Share

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?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vexe · Mar 03, 2014 at 12:53 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Determine difference between Undo and Redo operations 1 Answer

Testing for null, bug or feature? 2 Answers

Is there any way to successfully cast a UnityEngine.Object to a System.Object? 1 Answer

Is there a reason not to inherit from UnityEngine.Object if I wanted the basic functionalities that UE.Object gives? 1 Answer

Hooking Undo / RegisterUndo 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges