EllanJiang/GameFramework · error · GameFrameworkException
FSM owner is invalid.
Error message
FSM owner is invalid.
What it means
Fsm<T>.Create(string, T, params FsmState<T>[]) builds a new finite state machine bound to an owner object. The owner is mandatory because the FSM forwards it to every state's callbacks. A null owner fails the guard at Fsm.cs:138 and throws this exception before any state is initialized.
Solutions
- Pass the actual owner instance (usually 'this' from the component that owns the FSM).
- Ensure the owner object is constructed/initialized before creating the FSM (e.g. create the FSM in Start/OnInit rather than a field initializer).
Example fix
// before
m_Fsm = Fsm<MyComponent>.Create("MyFsm", null, new StateA(), new StateB());
// after
m_Fsm = Fsm<MyComponent>.Create("MyFsm", this, new StateA(), new StateB()); Defensive patterns
Strategy: validation
Validate before calling
if (owner == null) { throw new InvalidOperationException("FSM owner must be constructed before Create."); }
var fsm = Fsm<MyComponent>.Create("MyFsm", owner, states); Type guard
bool HasOwner<T>(T owner) where T : class => owner != null;
Try / catch
try { m_Fsm = Fsm<MyComponent>.Create(name, this, stateA, stateB); }
catch (GameFrameworkException ex) { Log.Error("FSM creation failed: " + ex.Message); } Prevention
- Create the FSM in a lifecycle method (Start/OnInit) where 'this' is guaranteed valid, not in a field initializer.
- Never pass null as owner — the FSM hands the owner to every state callback.
When it happens
Trigger: Calling Fsm<T>.Create(name, null, state1, state2, ...) with a null owner via the params-array overload.
Common situations: Creating an FSM inside a component's constructor or field initializer before the owner instance exists; passing a null after a failed dependency-injection lookup; using Create in a static context where the owner is not yet assigned.
Related errors
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/e301858ad965a745.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Fsm/Fsm.cs:138
{
get
{
return m_CurrentStateTime;
}
}
/// <summary>
/// 创建有限状态机。
/// </summary>
/// <param name="name">有限状态机名称。</param>
/// <param name="owner">有限状态机持有者。</param>
/// <param name="states">有限状态机状态集合。</param>
/// <returns>创建的有限状态机。</returns>
public static Fsm<T> Create(string name, T owner, params FsmState<T>[] states)
{
if (owner == null)
{
throw new GameFrameworkException("FSM owner is invalid.");
}
if (states == null || states.Length < 1)
{
throw new GameFrameworkException("FSM states is invalid.");
}
Fsm<T> fsm = ReferencePool.Acquire<Fsm<T>>();
fsm.Name = name;
fsm.m_Owner = owner;
fsm.m_IsDestroyed = false;
foreach (FsmState<T> state in states)
{
if (state == null)
{
throw new GameFrameworkException("FSM states is invalid.");
}
View on GitHub (pinned to d0c010b051)