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 11, 2016 at 07:17 PM by SkandYxyz for the following reason:

The question is answered, right answer was accepted

avatar image
2
Question by SkandYxyz · Aug 09, 2016 at 05:52 PM · scripting problemmonobehaviour

OnValidate() not called Unity 5.1.0f3

OnValidate() is only called upon script load or change from edit to play mode. Why? Not working in 5.3.5 neither. When i change values in my script, OnValidated should be called, but it's not.

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

2 Replies

  • Sort: 
avatar image
3
Best Answer

Answer by SkandYxyz · Aug 11, 2016 at 07:17 PM

In my case the problem was, that I used a custom editor. When you use a custom editor, the OnValid() function is not called anymore automatically. Thus, you need to call it e.g., when a parameter changed or in the OnInspectorGUI() function, if it's no matter if it's called more often.

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 IgorAherne · Apr 14, 2017 at 09:25 AM 0
Share

ty, awarded 50

avatar image
1

Answer by Holy_Crapf · Aug 09, 2016 at 06:36 PM

Just to be clear, the problem is that it's not being called during editor mode right? Because if the problem is that it's not being called in runtime, then that's because it's not supposed to be called then.

Comment
Add comment · Show 5 · 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 SkandYxyz · Aug 09, 2016 at 06:47 PM 0
Share

It's not called in editor mode.

But I just created a test monobehaviour script and there it works. (First, OnValidate() also seemed not to be called). In my script it still won't work.

avatar image Holy_Crapf SkandYxyz · Aug 09, 2016 at 07:08 PM 0
Share

And it's inheriting from $$anonymous$$onoBehaviour? Any chance you could show the script that the problem occurs in?

avatar image SkandYxyz Holy_Crapf · Aug 09, 2016 at 07:16 PM 0
Share

Thank you for your ideas! I am sorry, I don't want to post the code. But I realized, if I create a new script with the exact same content it works. $$anonymous$$aybe it has to do with script serialization? $$anonymous$$aybe I try to reimport everything.

No, that wasn't the problem. I guess I am near the problem. I have a CustomEditor class for this $$anonymous$$onoBehaviour and i guess I need to handle OnValidate() there.

Yes, it works when I remove the customer editor script.

I can post this piece of code - what do I need to do to call the OnValidate function? :

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 /// <summary>
 /// Custom Editor for the Billboard Script
 /// </summary>
 [CustomEditor(typeof(Billboard))]
 [CanEdit$$anonymous$$ultipleObjects]
 public class BillboardCustomEditor : Editor 
 {
     /// <summary>
     /// Called to display custom GUI
     /// </summary>
     public override void OnInspectorGUI()
     {
         // The referenced Billboard script
         Billboard _referenceBillboard = (Billboard)target;
         // Display and retrieve billboard class as string
         _referenceBillboard._billboardClass = EditorGUILayout.TextField("Billboard Class", _referenceBillboard._billboardClass);
         // Display and retrieve target game object
         _referenceBillboard._targetGameObject = EditorGUILayout.ObjectField("Target Game Object",_referenceBillboard._targetGameObject,typeof(GameObject),true) as GameObject;
         // Display and retrieve size integer
         _referenceBillboard._size = EditorGUILayout.IntField("Size",_referenceBillboard._size);
         // Display and retrieve count integer
         _referenceBillboard._count = EditorGUILayout.IntField("Count",_referenceBillboard._count);
         // Display and retrieve y-offset float
         _referenceBillboard._yOffset = EditorGUILayout.FloatField("Y Offset",_referenceBillboard._yOffset);
         // Display and retrieve zoomfactor float
         _referenceBillboard._zoomFactor = EditorGUILayout.FloatField("Zoom Factor",_referenceBillboard._zoomFactor);
         // Check, wether to display dynamic lighting values or not.
         if(_referenceBillboard._displayDynamicLightingValues)
         {
             SerializedProperty tps = serializedObject.FindProperty ("_dynamicLighting$$anonymous$$aterialSettings");    
             //EditorGUILayout.LabelField("Dynamic Lighting",EditorStyles.boldLabel);
             EditorGUILayout.PropertyField(tps,true);
         }
     }
 }

I can add this line and it will call the missing OnValidate() function, but to often - always on redraw.

     // Call on validate function
     _referenceBillboard.OnValidate();

Where can i put it to only call it when values change?

Show more comments

Follow this Question

Answers Answers and Comments

65 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

Related Questions

How to call invoke from a monobehaviour class using a function from an object class. 1 Answer

OnDisable and OnDestroy Not Get Called - iOS 2 Answers

I'm getting a warning in Unity about trying to create a MonoBehaviour using the "new" keyword. How do I fix it? 1 Answer

Trying to get access to variables in the editor script 4 Answers

Enabling multiple Monobehaviour Components in a game object 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