Case Status
Log In


Home ยป API Reference»Writing Custom Actions»Custom Actions Hints and Tips
Community Wiki

Custom Actions Hints and Tips

Cache GetComponent Calls

When using Fsm Variables you should assume that their value could change over the lifetime of the Action. In a MonoBehaviour you might cache a Component reference in Start(). In an Action this is risky, since the target might change and the Component is no longer the one you want.

Instead use this pattern to cache the component whenever the target GameObject changes:

Note: That snippet also shows a useful pattern to implement the Every Frame option. Put your action in a separate method that can be called from both OnEnter and OnUpdate. 

Use Action Subclasses for Related Actions

If you have a set of actions with shared features it can be useful to create a subclass of FsmStateAction with those shared features. Then each action in the set can derive from that subclass instead of FsmStateAction. See the GUILayout actions as an example.

Make Sure Your Action Class is Public

If you don't see your custom action in the Action Browser, make sure it is public!




Last modified on 1/7/2016 6:43 PM by User.

  • RSS Feed