Search Unity

Help please with Animation Component public properties custom inspector.

Discussion in 'Editor & General Support' started by Stephan-B, Feb 19, 2014.

  1. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    I have a custom inspector for a custom component. In the animation view, I can see all my public properties. I can create an animation (curve) to animate any of these properties. I can see the values of these properties change in the custom inspector however, these changes don't appear to go through {get; set;} nor do these changes result in (GUI.Changed) for the serialized fields of those properties ...

    How do I know what properties are being changed by the animation? Short of having to check every single public property to compare old vs. new value. Isn't that the point of the accessors?
     
    Last edited: Feb 19, 2014
  2. Dave-Hampson

    Dave-Hampson

    Unity Technologies

    Joined:
    Jan 2, 2014
    Posts:
    150
    I would presume that is because these are being updated by the engine animation system directly.

    I guess you might have to do that.
     
  3. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Thanks for the reply Dave :)

    What is the reason again for those components (like the animation one) bypassing the property accessors?

    Another question if I may. The animation system does detect when I edit any of the serialized fields in the editor. However, it does not detect when material properties of my custom material editor are changed. Any reason why?
     
  4. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    I ticked on the {get; set;} part. Do you use implicit properties or do you manually declare a backing field?
     
  5. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Code (csharp):
    1.  
    2. // TEXT INPUT
    3. public string text
    4. {   get { return m_text; }
    5.     set { if (m_text != value) { havePropertiesChanged = true; isAffectingWordWrapping = true; m_text = value; } }
    6. }
    7. [SerializeField]
    8. private string m_text;
    Users can set the text via script and access textMeshPro.text while the custom inspector modifies m_text and sets the appropriate flags. The animation component simply changes the value of .text bypassing the set;
     
    Last edited: Feb 20, 2014
  6. andsee

    andsee

    Joined:
    Mar 20, 2012
    Posts:
    88
    Did you get anywhere with this? I'm just about to attempt the same thing and have accessors for parameters that kick off changes in the component in a similar way. I do not wish to check my serialised fields nor make them public either.
     
  7. andsee

    andsee

    Joined:
    Mar 20, 2012
    Posts:
    88
    I may have just found the answer which currently has no hits on google and is undocumented. Hopefully it's added to the docs soon. Anyway the following is working for me in Untiy4.6 beta.

    Add OnDidApplyAnimationProperties() to your component and it is called just when we need it to, after an animation modifies a serialised value.

    Use [ExecuteInEditMode] to get it to work in animation previews.

    I also tried using the new serialisation callbacks introduced in 4.5 but these were not called by the animation system.
     
  8. cecarlsen

    cecarlsen

    Joined:
    Jun 30, 2006
    Posts:
    862
    I just checked and this method is still undocumented. It is documented for LayoutGroup and UIBehaviour, but not MonoBehaviour. Why why why?
     
    Noisecrime, Democide and ModLunar like this.
  9. danUnity

    danUnity

    Joined:
    Apr 28, 2015
    Posts:
    229
    Oh, interesting! Been trying to find a solution to that problem for ages! So its surprising there's not much about that issue on the forum or anywhere for that matter. It's such a fundamental problem...

    So with OnDidApplyAnimationProperties() you would call a function that contains the same code that your setter is doing?
     
    KingTeehl likes this.
  10. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    Weird, this is not getting called in any way at all for me, including the following:

    1. In playmode
    2. In edit mode with the AnimationWindow previewing
    3. In edit mode with the AnimationWindow recording

    Are we sure this still works in a MonoBehaviour script?

    Code (CSharp):
    1. private void OnDidApplyAnimationProperties() {
    2.     Debug.Log(name + " OnDidApplyAnimationProperties()");
    3. }
     
  11. april_4_short

    april_4_short

    Joined:
    Jul 19, 2021
    Posts:
    489
    If you remove the "private" keyword" it might get called.

    Still working in 2019.4LTS, I've been leaning heavily on this for a while.

    Works in Editor mode, to, or can be called by an OnValidate when editing.