Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Aug 02, 2016 at 08:56 AM by xRoachx for the following reason:

Problem is not reproducible or outdated

avatar image
2
Question by xRoachx · Aug 01, 2016 at 03:05 PM · editorarraycustom editorundorecord

Undo.Record: Recording variables within array elements

I created an custom editor button that takes an TextField and creates a new Element in an array.

The array elements are the following class:

 [System.Serializable]
 public class NPCDialogueSettings {
     public string name; 
     public int order; 
 
     [Header("Flags")]
     public FlagNode[] flagsToCheck; //If these conditions are met the dialogue can be executed
     public FlagNode[] flagsToSet; //After dialogue these flags are set true or false
     [Header ("Execution Conditions")]
     public bool playOnce = false; 
 }

I can easily create a new element in the array and save it using Undo.RecordObject. But changing a variable in one of the elements is not saved.

Is there a way to save variables in array elements (Which is a class) using Undo.RecordObject or some other method?

More complete code of the actual function: (Note that I am trying to save: Name and Order)

  //==================Create new DialogueSettings in NPC Dialogue Controller==================
         NPCDialogueSettings[] dialogueSettingsArray = dialogueControllerRef.dialogueSettings;
         NPCDialogueSettings[] tempDialogueSettingsArray = new NPCDialogueSettings[dialogueSettingsArray.Length + 1];
 
         for (int i = 0; i < dialogueSettingsArray.Length; i++) {
                 tempDialogueSettingsArray[i] = dialogueSettingsArray[i];
                 tempDialogueSettingsArray[i].order = i;
         }
 
         int lastElement = tempDialogueSettingsArray.Length -1;
 
         //Create new NPCDialogue on last element
         tempDialogueSettingsArray[lastElement] = new NPCDialogueSettings();
 
         //Set the vars in new dialogue
         tempDialogueSettingsArray[lastElement].name = newDialogueName;
         tempDialogueSettingsArray[lastElement].order = dialogueSettingsArray.Length;
 
 
         //Record
         Undo.RecordObject(dialogueControllerRef, "Record NPC Dialogue Controller");
         //Set the new array
         dialogueControllerRef.dialogueSettings = tempDialogueSettingsArray;

 




Comment
Add comment · Show 4
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 Glurth · Aug 01, 2016 at 04:05 PM 0
Share

Hmm, I think we may need some clarification, not quite clear what this means: "But changing a variable in one of the elements is not saved."

avatar image xRoachx · Aug 01, 2016 at 06:01 PM 0
Share

Okay, so I have a array in a gameobject. That array consists out of the NPCDialogueSettings (The first code above).

The editor button Adds an array element to the list (By copying the existing array and just making it one bigger (Dind't want a list)

If I do for example: tempDialogueSettingsArray[AnyElement].name = "Some string"

Than replace the existing string (dialogueControllerRef.dialogueSettings = tempDialogueSettingsArray;) The elements amount is saved (Thus the array is now 1 element bigger). The name also changed but is reset if pressing play and going back to editor again. (So the record doesn't work).

Now I am looking a lot as this: https://docs.unity3d.com/ScriptReference/EditorUtility.SetDirty.html

And I know I probably have to use SerializedObject or the likes but can't seem to wrap my head around it and can't find proper documentation.

avatar image Glurth xRoachx · Aug 07, 2016 at 03:57 PM 0
Share

Do those array's exist in the EDITOR's class? Those are NOT automatically saved like say.. a scene or pre-fab object's data would be. Rather they are reinitialized on load or play.

avatar image SarfaraazAlladin · Feb 08, 2017 at 09:30 PM -1
Share

I have a similar problem - I want to replace a group of objects that a user has defined via an array of game objects.

  1. User populates an array via an editor window

  2. User drags the object they want to use as a replacement

  3. User hits 'replace' and the array of objects is replaced by copies of the replacement

This works great, but when they undo the array is left with $$anonymous$$issing References. (even though the object replacements are properly undone.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Custom Editor + Array = A Long Nightmare ! 1 Answer

Custom Editor for array of custom class 1 Answer

Custom editor array without serialized object 2 Answers

Undo.RecordObject doesn't work 2 Answers

Custom Editor serializing data in prefab instance. 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