Event Parameters

The standard UltEvent class allows you to register methods with predefined values, but doesn't let you pass in custom parameters when the event is invoked. For example, you could have an event that instantiates a prefab at a specific location you set in the event's Inspector, but you couldn't use the information from an OnCollisionEnter message to have your event instantiate the prefab at the point where the collision occurs. To do this, you need to use the generic versions of UltEvent instead.

To use a generic event type you must first create a serializable class that inherits from the desired event type. For example, if you want an event that takes a Vector3 parameter, you would write the following:

[Serializable]
public sealed class Vector3Event : UltEvents.UltEvent<Vector3> { }

Then you can use that event type instead of the regular UltEvent when declaring your event field:

[SerializeField]
private Vector3Event _MyEvent;

And when you want to invoke the event you will need to pass in the required parameters:

_MyEvent.Invoke(transform.position);
_MyEvent.Invoke(Vector3.zero);
_MyEvent.Invoke(new Vector3(...));
// Etc.

When using the Inspector to configure an event with parameters, any method parameters with the appropriate type will show a [∞] button which toggles that parameter between linked (so it receives the value you pass into the Invoke call) and unlinked (so you can use the Inspector to specify its value normally).

If you specify a parameter type that isn't normally supported by UltEvents such as UltEvent<Collision> or UltEvent<SomeCustomClass>, you will be able to select methods with that parameter type which would not normally appear in the list. Such parameters are automatically linked and can't be unlinked.