Creating custom FSM

Whenever you want light-weight coding entities I recommend USTRUCTS, then you need at most 1 UObject or Actor manager of your system to tick all your USTRUCTs

UStructs, They Are Awesome!
https://wiki.unrealengine.com/Structs,_USTRUCTS(),_They're_Awesome


**Thousands of UE4-Integrated Stale-Pointer Protected, Light-weight Entities**

This way you can comfortably make 2000+ states with their own instanced variables and proper entitization, and you will have a very stable system that is also light-weight, as with USTRUCTS you can pass everything by reference :)

Keep in mind though with USTRUCTS you still get stale UObject Ptr protection, as long as you store your UStruct State array in a UObject or AActor class and mark it with UPROPERTY().

GameState would be a good place to store your state array :)




```


UPROPERTY() //<~~~~ Gives you GC protection and stale ptr protection if you have ptrs to UObjects inside of FYourState
TArray<FYourState> FSM;


```



But if your FSM is per actor then you can do this same thing in your actor class

then override Actor tick and have it tick each of your USTRUCTS



```


FYourState::Tick(float DeltaSeconds)
{
   //Now you are fully hooked into the awesomeness that is UE4 while having instanced vars in a by-ref (more stable than ptrs) GC-protected data format.
}


```


Rama

PS: More on Stale Ptr Protection and GC

https://wiki.unrealengine.com/How_To_Prevent_Crashes_Due_To_Dangling_Actor_Pointers

https://wiki.unrealengine.com/Garbage_Collection_%26_Dynamic_Memory_Allocation