FP Event is a small, package-friendly event layer for Unity projects. It combines ScriptableObject event data, MonoBehaviour event emitters, and a singleton event manager so other FuzzPhyte packages can share a common event pattern.
The package is intended to sit underneath higher-level systems such as inventory, dialogue, graph, network, XR, and gameplay packages.
FPEvent: an abstract event data asset that inherits fromFP_Data.FPEventComponent<T>: a MonoBehaviour wrapper that triggers anFPEvent.FP_EventManager<T>: a persistent singleton manager that records triggered event components and can process manager-side callbacks.Samples~/SamplesURP: simple starter classes and a sample scene showing the generic pattern.
- Unity
6000.4or newer. com.fuzzphyte.utility, because the runtime assembly referencesFuzzPhyte.Utility.- Unity packages listed in
package.json, includingcom.unity.mathematicsandcom.unity.textmeshpro.
See Installation~/Dependencies.md for the FP Utility dependency note.
FPEvent is the base class for all event data assets.
- Inherits from
FP_Data, which suppliesUniqueID. - Stores a
Priorityvalue used for event ordering. - Requires derived event types to implement
Execute(object data = null). - Implements
IComparable<FPEvent>so events can be sorted by priority.
FPEventComponent<T> is the bridge between a scene object and an event asset.
- Assign
GameEventin the Inspector. TriggerEvent()invokesOnEventTriggered.- The default
Awake()wiresOnEventTriggeredto the component'sExecuteEvent(). - After local execution,
TriggerEvent()records the component withFP_EventManager<T>.Instance. - Derived classes provide event data through
GetEventData(), immediate behavior throughExecuteEvent(), and manager-side behavior throughManagerEvent().
FP_EventManager<T> records triggered components and can process them later.
- Keeps one persistent singleton instance per event type.
- Uses
DontDestroyOnLoad. - Records triggered components in insertion order by default.
- Can use a priority queue if a derived manager enables
UsePriorityQueue. - Calls each recorded component's
ManagerEvent()whenProcessRecordedManagerEvents()runs.
Create a concrete event data asset:
using FuzzPhyte.SystemEvent;
using UnityEngine;
[CreateAssetMenu(menuName = "FuzzPhyte/Events/Door Event")]
public class DoorEvent : FPEvent
{
public override void Execute(object data = null)
{
Debug.Log($"Door event executed with data: {data}");
}
}Create a component that triggers the event:
using FuzzPhyte.SystemEvent;
using UnityEngine;
public class DoorEventComponent : FPEventComponent<DoorEvent>
{
protected override object GetEventData()
{
return gameObject;
}
protected override void ExecuteEvent()
{
GameEvent.Execute(GetEventData());
}
public override void ManagerEvent()
{
Debug.Log($"Manager processed {GameEvent.name}");
}
}Create a manager for that event type:
using FuzzPhyte.SystemEvent;
using UnityEngine;
public class DoorEventManager : FP_EventManager<DoorEvent>
{
private void Update()
{
ProcessRecordedManagerEvents();
}
}Then in Unity:
- Create a
DoorEventasset from the Create Asset menu. - Add
DoorEventManagerto one GameObject in the scene. - Add
DoorEventComponentto any GameObject that should fire the event. - Assign the
DoorEventasset to the component'sGameEventfield. - Call
TriggerEvent()from gameplay code, UI, animation events, or another UnityEvent.
Caller
-> FPEventComponent<T>.TriggerEvent()
-> UnityEvent OnEventTriggered
-> FPEventComponent<T>.ExecuteEvent()
-> FP_EventManager<T>.RecordEvent(component)
-> FP_EventManager<T>.ProcessRecordedManagerEvents()
-> FPEventComponent<T>.ManagerEvent()
Use ExecuteEvent() for immediate local behavior and ManagerEvent() for behavior that should be coordinated by a manager.
Priority is compared in ascending order. When a manager uses the priority queue,
lower priority values are dequeued first. The base manager keeps UsePriorityQueue
disabled, so derived managers should opt in when priority processing is needed.
public class PriorityDoorEventManager : FP_EventManager<DoorEvent>
{
public override void Awake()
{
base.Awake();
UsePriorityQueue = true;
}
}Import Samples~/SamplesURP through Unity Package Manager to inspect:
EventDataSample: minimalFPEventimplementation.EventFPSample: minimalFPEventComponent<FPEvent>implementation.EventMgrSample: minimalFP_EventManager<FPEvent>implementation.EventTest.unity: sample scene.
These samples are intentionally lightweight and are best used as inheritance templates.
When creating events for another package:
- Derive a specific event data type from
FPEvent. - Derive a matching component from
FPEventComponent<TEvent>. - Add exactly one matching
FP_EventManager<TEvent>instance to the active scene or bootstrap flow. - Keep event assets reusable and scene-independent.
- Pass scene-specific context through
GetEventData()instead of storing scene references on the asset.
Please see package.json for Unity package dependencies.
Runtime assembly reference:
com.fuzzphyte.utility
See LICENSE.md for details.