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 /
  • Help Room /
This question was closed Aug 17, 2017 at 03:54 PM by haruna9x for the following reason:

Problem is not reproducible or outdated

avatar image
2
Question by haruna9x · Jul 11, 2017 at 01:30 PM · editoreditorguilayout

EditorGUILayout.FloatField return strange value when it is repaired elsewhere

 public class StatBase
 {
  [SerializeField] private float _baseValue;
 
  public virtual float BaseValue
         {
             get { return _baseValue; }
             set
             {
                 Debug.Log(value - _baseValue);
                 _baseValue = value;
             }
         }
 }
 
 public class StatAttribute : StatBase
 {
 [SerializeField] private int _statLinkerValue;
 public override float BaseValue
         {
             get
             {
                 if (base.BaseValue + StatLinkerValue < MinValue)
                     return MinValue;
                 else if (base.BaseValue + StatLinkerValue > MaxValue)
                     return MaxValue;
                 else
                     return base.BaseValue + StatLinkerValue;
             }
         }
 }
 
 public class EntityEditor : Editor
 {
 public override void OnInspectorGUI()
 {
         showBase = EditorGUILayout.Toggle("Show Base Value", showBase);
         if (showBase)
         {
             stat.BaseValue = EditorGUILayout.FloatField("Base Value", 
             stat.BaseValue);
             GUILayout.Space(10);
         }
 }
 }


stat variable is a StatAttribute, They have a method that updates the value of StatLinkerValue that I will call from the editor (Update button). Everything works fine when I click the Update button, StatLinkerValue varies from 0 to 100, but somehow the editor has repeatedly added the _baseValue 100 until it equals MaxValue. This error will not occur if I do not present the BaseValue in the Editor, so I added a toggle to turn it off before performing the update.Everything went well, but when I turned on Toggle again, _baseValue immediately increased. I have spent quite a long time without understanding what is happening, I have not assigned _baseValue to any form other than stat.BaseValue = EditorGUILayout.FloatField ("Base Value", stat.BaseValue); Inside Editor. Finally sorry for my english.

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

  • Sort: 
avatar image
2
Best Answer

Answer by haruna9x · Jul 12, 2017 at 11:51 AM

 public class BaseTest
     {
         float _baseValue;
     
         public virtual float BaseValue
         {
             get { return _baseValue; }
             set { _baseValue = value; }
         }
     }
     
     public class AttributeTest : BaseTest
     {
         float _linkerValue;
     
         public float LinkerValue
         {
             get { return _linkerValue; }
             set { _linkerValue = value; }
         }
     
         public override float BaseValue
         {
             get { return base.BaseValue + LinkerValue; }
         }
     
         public void UpdateLinker()
         {
             _linkerValue += 10;
         }
     }
     
     public class StatTest : MonoBehaviour
     {
         AttributeTest _attack;
     
         public AttributeTest Attack
         {
             get { return _attack; }
             set { _attack = value; }
         }
     
         public StatTest()
         {
             Attack = new AttributeTest();
         }
     }
     
     [CustomEditor(typeof(StatTest))]
     public class EditTest : Editor
     {
     
         StatTest data;
     
         private void OnEnable()
         {
             data = target as StatTest;
         }
     
         public override void OnInspectorGUI()
         {
         
             data.Attack.BaseValue = EditorGUILayout.FloatField("Base Value", data.Attack.BaseValue);
             data.Attack.LinkerValue = EditorGUILayout.FloatField("Linker Value", data.Attack.LinkerValue);
     
             if (GUILayout.Button("Update"))
             {
                 data.Attack.UpdateLinker();
             }
         }
     }


Seems in the end I found out the reason. An error will occur whenever I let the BaseValue and Linker Value at the same time as in the above example, Editor has mistakenly something with BaseValue override.

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

Follow this Question

Answers Answers and Comments

126 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

Related Questions

How do I use EditorGUILayout.EnumPopup with an enum with 'holes' in a custom inspector. 3 Answers

Unity automatically resets my gameview scale back to 1. How do I stop this? 0 Answers

How can I display a scriptable object in a custom editor ? 1 Answer

EditorGUILayout.EnumPopup shows always the same selected option but works as programmed 1 Answer

Adding space() to BeginHorizontal() causes extra vertical spacing after certain amount. 1 Answer


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