Unity Events with dynamic values

Something that's easily missing is the top "Dynamic" section in the function selection.

How can I pass a UnityEvent value to a script?

Let's say you have this very simple script:

using UnityEngine;

public class SliderReceiver : MonoBehaviour
{
    public void LogSliderValue(float value)
    {
        Debug.Log(value);
    }
}

If you want your dynamic value to be passed over then you have to pick from those in the top list, not the bottom.

It's easy to miss since the bottom list event shows the "float" parameter but all this means is that you will have to set that parameter statically. That's not what we want. Use the option at the top instead and you will get your dynamic value:

Asset Recommendations

Here are some assets that may be useful to you. If you get one of them then a small part of the money you spend will also help fund this project. Thank you.

Disclosure: This text may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we have recommended. While clicking these links won't cost you any money, they will help fund this project! The links are created by Unity and Partnerize (Unity's affiliate partner).

Related Articles

Let the AI write the code

AIs have been all the rage for a while now. And rightfully so. Language AIs like ChatGPT are powerful tools and they are here to stay.
Read article ..