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 /
  • Help Room /
avatar image
0
Question by GingerbreadFetus · Oct 31, 2020 at 09:18 AM · editor-scriptingcustom editor

Custom Editor Handle Changes Not Persisting in Play Mode.

Really hoping that somebody can just help me make sense of this. I'm trying to make a custom handle that will act as a bounding box for the actors moving around in it. Like an animal pen. I pretty much followed the documentation for BoxBoundsHandles and made some changes to get the behavior I want. (Following the transform gizmo, etc.)

The issue is, as you'll see in the console screenshot, that as soon as I press play, the changes I'm making to the bounds seem to reset to these values and I don't know why.alt text They don't change in the scene view, the bounding box stays the same size.

Here is the code for reference (I've made some sloppy changes to it trying to figure out what is going on.):

 [CustomEditor(typeof(Hatchery))]
 public class HatcheryBounds : Editor
 {
     private BoxBoundsHandle m_BoundsHandle = new BoxBoundsHandle();
 
     protected virtual void OnSceneGUI()
     {
         Hatchery hatchery = (Hatchery)target;
 
         // copy the target object's data to the handle
         m_BoundsHandle.center = hatchery.transform.position;
         m_BoundsHandle.size = hatchery.Extents;
         // draw the handle
         EditorGUI.BeginChangeCheck();
         m_BoundsHandle.DrawHandle();
 
         if (EditorGUI.EndChangeCheck())
         {
             // record the target object before setting new values so changes can be undone/redone
             Undo.RecordObject(target, "Change Hatchery Bounds");
 
             // copy the handle's updated data back to the target object
             Debug.Log("Hatchery bounds started as: " + hatchery.bounds);
             Bounds newBounds = new Bounds();
             newBounds.center = m_BoundsHandle.center;
             newBounds.size = m_BoundsHandle.size;
             hatchery.Extents = newBounds.size;
             hatchery.transform.position = newBounds.center;
             hatchery.bounds = newBounds;
             Debug.Log("Hatcher bounds changed to: " + hatchery.bounds);
         }
     }
 }

custom-editor-issue.jpg (33.3 kB)
Comment
Add comment
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

1 Reply

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

Answer by GingerbreadFetus · Nov 01, 2020 at 09:30 AM

I discovered that the source of this problem was with the default values that I was setting up the hatchery object with: Where I was initially setting it something like:

 Bounds m_Bounds = new Bounds(vector.zero, vector.one);

Changing it to:

  void Start()
         {
             bounds = new Bounds(transform.position, extents);
             Debug.Log("Hatchery bounds are: " + bounds);
             for (int i = 0; i < maxFish; i++)
             {
                 SpawnNewFish();
             }
         }

This seems to have fixed the problem. I understand this is because I misunderstood the order in which Unity sets variables. So on start, rather than keeping the variables I had set in the inspector, it was resetting to the 'default' because I never told it to read the values....

That doesn't sound quite right, anybody feel free to correct me or explain it better.

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

221 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 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 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 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

Popup to choose which child class I want in Custom Editor Inspector 0 Answers

How to make a dropdown in Unity Editor with list from another Monobehaviour Script 0 Answers

ScriptableObject not Serializing? 0 Answers

Why is my Custom Inspector Causing Performance Issues? 0 Answers

How to edit array/list property with custom PropertyDrawer? 3 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