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 /
avatar image
0
Question by Double-V · Aug 23, 2017 at 08:30 PM · valuesoverrideeditor extensionvirtual functions

Weird behaviour of an editor extension that sets variables on other scripts.

I have an editor extension that generates unique ids for objects with selected tags, I needed to make it since unity doesn't have a reliable id system to use in a save/load funcionality. the idea is that when i'm done with making a level I run the ID dispenser and everything that needs an id has it.

The problem is for all gameobjects with a few tags it works as intended, but for a few others it doesn't - it sets the id when I run the dispenser, but then when I hit play ids are set to = "". This is an example from the editor extension:

     string prefix_pickup = "P-";
 
 void DispenseIDToPickups()
     {
         if(prefix_pickup == null || prefix_pickup == "")
         {
             return;
         }
         GameObject[] pickups = GameObject.FindGameObjectsWithTag("Pickup");
         string id = "";
         for (int i = 0; i < pickups.Length; i++)
         {
             id = prefix_pickup + i.ToString("D6");
             pickups[i].GetComponent<PickupFunctionPasser>().SetUniqueID(id);
         }
     }


PickupFunctionPasser is just a class from which all pickups inherit in my project, it has a bunch of virtual voids, so you can run override voids on those pickups through those virtual voids.

Now this is what sits on an example pickup:

 [HideInInspector]
     public string id;
 
 public override void SetUniqueID(string passed_id)
     {
         id = passed_id;
         Debug.Log("id for " + gameObject.name + " is " + id);       
     }
 
     public override string GetUniqueID()
     {
         return id;
     }


That debug.log actually returns the id that is supposed to be there, so the system works, untill i press play - then the id = ""; How do I make it stay there? And why does it stay on some other objects even though they use a setup like that?

EDIT: So I've tried using the Undo.RecordObjects and Undo.RecordObject this way:

 void DispenseIDToPickups()
     {
         if(prefix_pickup == null || prefix_pickup == "")
         {
             return;
         }
         GameObject[] pickups = GameObject.FindGameObjectsWithTag("Pickup");
         Undo.RecordObjects(pickups, "assigning ids");
         string id = "";
         for (int i = 0; i < pickups.Length; i++)
         {
             id = prefix_pickup + i.ToString("D6");
             
             pickups[i].GetComponent<PickupFunctionPasser>().SetUniqueID(id);
         }
     }

And this:

 void DispenseIDToPickups()
     {
         if(prefix_pickup == null || prefix_pickup == "")
         {
             return;
         }
         GameObject[] pickups = GameObject.FindGameObjectsWithTag("Pickup");
         string id = "";
         for (int i = 0; i < pickups.Length; i++)
         {
             id = prefix_pickup + i.ToString("D6");
             Undo.RecordObject(pickups[i], "Assigned id");
             pickups[i].GetComponent<PickupFunctionPasser>().SetUniqueID(id);
         }
     }

And the id is still set to ="" when pressing play.

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 RiQQ92 · Aug 24, 2017 at 09:28 AM 1
Share

By the looks of it, im guessing its saving/serialization problem. So if you are doing these to scene objects you have to save the scene in order to save the changes. I'm not sure but you could probably use these in your script to fix the random saving:

  • EditorScene$$anonymous$$anager.$$anonymous$$arkSceneDirty

  • EditorScene$$anonymous$$anager.SaveScene

You should probably only run those from custom editor, hope it helps.

avatar image Double-V RiQQ92 · Aug 24, 2017 at 02:14 PM 0
Share

I run both of those and it still gets reset.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by FortisVenaliter · Aug 24, 2017 at 04:30 PM

Check out this article. Looks like Unity may have changed the way you mark changes since 5.3. Instead of MarkDirty, you need to use the Undo system.

Comment
Add comment · 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

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

69 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 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 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 avatar image avatar image avatar image

Related Questions

Are inspector values supposed to override [HideInInspector] code? 1 Answer

Can't Override Virtual Method In Inherited Class 1 Answer

Question about Overriding Functions 1 Answer

How to assign a joint's 'connected body'? 1 Answer

Asset Store EULA 2.4 2 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