keijiro/MidiAnimationTrack

Unable to target public float property on custom Mono Behaviour

Closed this issue · 4 comments

Hi Keijiro

I'm using this package (1.0.4) with Unity 2020.3.15f2.

Everything works as expected when using a control element to target a property on a built-in component such as a Transform, Camera or Light.

When I select a custom script (MonoBehaviour) as the target, there is no 'Property' drop-down available for me to select the desired target property in my script. I am using public (float) properties, not just public variables as advised in your documentation.

Is controlling public properties on custom scripts an intended feature and if so, do you have any advice as to why I am unable to access them via the inspector?

Many thanks for all your work as always!

Rob

The custom component I'm trying to target...

using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using Kino.PostProcessing;

public class PostProcessingEffector : MonoBehaviour
{

    [SerializeField] private VolumeProfile _volumeProfile;

    private float _bloomIntensityValue;
    public float BloomIntensityValue
    {
        get { return _bloomIntensityValue; }
        set { _bloomIntensityValue = value; }
    }

    public float StreakStretchValue { get; set; }

    private Bloom _bloomEffect;
    private Streak _streakEffect;

    private void Start()
    {
        _volumeProfile.TryGet<Bloom>(out _bloomEffect);
        BloomIntensityValue = 0.64f;

        _volumeProfile.TryGet<Streak>(out _streakEffect);
        StreakStretchValue = 0.8f;
    }

    void Update()
    {
        _bloomEffect.intensity.value = _bloomIntensityValue;
        _streakEffect.stretch.value = StreakStretchValue;
    }
}

Could you try this?

[SerializeField] float _bloomIntensityValue;
public float bloomIntensityValue
{
    get { return _bloomIntensityValue; }
    set { _bloomIntensityValue = value; }
}

Here is a hint for you.

https://github.com/keijiro/MidiAnimationTrack/blob/master/Packages/jp.keijiro.klak.timeline.midi/Editor/MidiEditorUtility.cs#L20

I implemented it to cover Unity's coding convention. You have to follow it to accept actions from MidiAnimationTrack.

@keijiro thank you very much for the quick response.

With the above amendment implemented, everything is now functioning as expected.

Ok. I could not make it work, but I understood why :

At first, I wrote which was not recognized.

[SerializeField] float test;
     public float Test 
     { 
         get { return test; } 
         set { test = value; }  
     }

But with

 [SerializeField] float _test;
    public float test 
    { 
        get { return _test; } 
        set { _test = value; }  
    }

It works