Dynamic float parameter not appearing

Even though the linked thread is marked at solved, it really isn’t, and the underlying issue isn’t addressed in the course.

The dynamic float parameter isn’t appearing in my version of unity either, and there is no alternative method suggested either in the video or linked thread.

Please recommend an alternative method! Thanks.

Short of changing versions, there’s not a way to get the dynamic link into the inspector if that version of Unity is not exposing it like it’s supposed to.

The alternate suggestion at the top of the post (the DamageTextSpawner finding the Health component and subscribing to the event) will always work, and is my recommended course of action. Hooking things up in the inspector is nice, when it works. This issue hasn’t come up in a while, and I haven’t been noticing it in any of the 2020 or 2021 versions I’ve tried.

Ah sorry, thanks, I only read the title of the post, and looked at the reply marked “solved by”, and the rest of the replies. I have since used:

 public event Action<int> OnTakeDamage;

 public void TakeDamage(GameObject _instigator, int amount)
        {
            currentHealth.value = Mathf.Max(currentHealth.value - amount, 0);
            if (!triggeredDeath) OnTakeDamage?.Invoke(amount);
            HandleDeath(_instigator);
        }

in the health component, and

    void Awake()
        {
            health = GetComponentInParent<Health>();
        }

        void OnEnable()
        {
            health.OnTakeDamage += Spawn;
        }

        private void OnDisable()
        {
            health.OnTakeDamage -= Spawn;
        }

        public void Spawn(int _damageAmount)
        {
            DamageText instance = Instantiate<DamageText>(damageTextPrefab, transform);
            instance.SetValue(_damageAmount);
        }

in the damage text spawner.

Thanks for your help once again!

System.Actions shouldn’t be appearing in the Inspector at all.

UnityEvents, on the other hand, should.

public UnityEvent<int> OnTakeDamage;

Then you should be able to set it in the inspector.
Subscribing/unsubscribing to UnityEvents is a bit different, though:

void  Awake()
{
     health = GetComponentInParent<Health>();
}

void OnEnable()
{
    health.OnTakeDamage.AddListener(Spawn);
}
 
void OnDisable()
{
    health.OnTakeDamage.RemoveListener(Spawn);
}

It should be noted that while the lectures on UnityEvents have you create a special class for the UnityEvent if it has parameters, Unity 2019 and onward removes this requirement.

Hi!

Yeah, I kind of forwent using Unity Events and decided to use vanilla C# Events for everything. This is how I did it.

Thanks for your help!

Privacy & Terms