Skip to main content

Generate Typed Event Assets in Unity

TinyGiants
Unity Games & Tools Developer

Choose the event signature based on the data a listener needs. Game Event Creator uses the signature to generate concrete Unity types for the event and its Inspector binding. Once Unity compiles them, assign the new event asset to the sender and receiver.

Choose an event signature​

Game Event Creator offers three signatures. Choose the smallest signature that supplies the data the listener needs.

Void Events: GameEvent​

Use a parameterless GameEvent for a signal such as level completion.

Creator Parameterless

[GameEventDropdown, SerializeField] private GameEvent onLevelComplete;

public void CompleteLevel()
{
onLevelComplete.Raise();
}

Single-argument events​

Use a single argument when the response needs a value, such as the updated score.

Creator Single

[GameEventDropdown, SerializeField] private Int32GameEvent onScoreChanged;

public void AddScore(int points)
{
currentScore += points;
onScoreChanged.Raise(currentScore);
}

Int32GameEvent is the concrete class generated from GameEvent<int>. Use it for serialized event fields and assign the created asset in the Inspector.

Sender + Args events​

Sender + Args signature in Game Event Creator

Use Sender + Args when several objects raise the same event and the callback needs to identify the sender. This example passes the damaged GameObject and its damage payload.

[GameEventDropdown, SerializeField] private GameObjectDamageInfoGameEvent onDamageTaken;

public void TakeDamage(DamageInfo info)
{
currentHealth -= info.amount;
onDamageTaken.Raise(gameObject, info);
}

Built-in signatures​

The package includes 32 generated single-argument event types, including int, float, bool, string, Vector3, Color, GameObject, and Transform. Select them directly in Creator.

Built-in argument types in Game Event Editor

If a raise needs to carry multiple related values, put them in a custom type. For example, a damage payload can group the amount, damage type, and impact position.

Generate a custom event type​

Select the parameter type in Game Event Creator. When the type has no generated wrapper, Creator generates it and waits for Unity to compile it before creating the event asset.

Create a single-argument event

For a custom DamageInfo argument, the event file defines a DamageInfoGameEvent : GameEvent<DamageInfo> and a serializable DamageInfoGameEventActionEntry : GameEventSingleActionEntry<DamageInfo>. GES also generates matching Raiser and Receiver components. A Sender + Args signature generates the corresponding two-argument wrappers.

Generate types in batches with CodeGen​

To generate wrappers in advance for several arguments or Sender + Args pairs, open the code generation tool under Tools & Utilities in Game Event System. Queue the types and generate the scripts in one operation.

Code tools in Game Event System

Before removing a custom argument type, check the associated events and scene references. Use the code cleanup tool to remove generated files you have confirmed are unused.

Pass a custom damage payload​

Define a runtime data type that holds the damage, impact position, and critical-hit flag together.

using System;
using UnityEngine;

namespace MyGame.Combat
{
[Serializable]
public struct DamageInfo
{
public float amount;
public Vector3 hitPoint;
public bool isCritical;
}
}

In Game Event Creator, choose the single-argument signature and DamageInfo. Create OnDamageTaken and wait for Unity to compile the generated types. Assign the new asset to the serialized event field below.

using MyGame.Combat;
using TinyGiants.GES.Runtime;
using UnityEngine;

public class Health : MonoBehaviour
{
[GameEventDropdown, SerializeField] private DamageInfoGameEvent onDamageTaken;
private float currentHealth = 100f;

public void TakeDamage(DamageInfo info)
{
currentHealth -= info.amount;
onDamageTaken.Raise(info);
}
}

In Game Event Behavior, select a receiver and a method that accepts DamageInfo in the Event Action list. Choose the dynamic binding to pass the event payload through. In Play Mode, call TakeDamage and check that the callback receives the amount you supplied.

Create a typed event