StateComponent

Provides a function to set the status behaviors and transition rules and control them using a custom StateType.

# Properties

[{"index":"string CurrentStateName (Sync) (ReadOnly) (HideFromInspector)","0":"You can get the name of the current state."}]

[{"index":"boolean IsLegacy (ReadOnly)","0":"Sets whether this Component operates with the legacy system.Depending on the setting, the state transition and the execution space of events defined in StateType and ConditionType may differ."}]

[{"index":"string StateSetId (ReadOnly)","0":"The Id of the StateSet to apply to the internal state machine of StateComponent.When using a StateSet, the addition and removal of states and conditions through the API is restricted."}]

##### inherited from Component:

[{"index":"boolean Enable (Sync)","0":"Checks whether Component is activated or not."}]

[{"index":"boolean EnableInHierarchy (ReadOnly) (HideFromInspector)","0":"Displays whether this Component is Enable in the hierarchy. If Entity Enable is false regardless of Component Enable, returns false."}]

[{"index":"Entity Entity (ReadOnly)","0":"The Entity that owns this component."}]

# Methods

[{"index":"boolean AddCondition(string stateName, string nextStateName, boolean reverseResult = false) (Deprecated)","0":"Connects stateName's status and nextStateName's status. Returns false if it fails. When the return value of StateType's OnConditionCheck is true, the status transitions from stateName to nextStateName. If reverseResult's value is true, a status transition occurs when OnConditionCheck's return value is false."}]

[{"index":"boolean AddCondition(string stateName, string nextStateName, func -> boolean conditionCheckFunction, boolean reverseResult = false) (Deprecated)","0":"This function is now deprecated. Use another AddCondition (string, string, boolean) function."}]

[{"index":"boolean AddState(string stateName, func updateFunction = nil) (Deprecated)","0":"This function is now deprecated. Use another AddState (string, Type) function."}]

[{"index":"boolean AddState(string stateName, Type stateType)","0":"Adds the status named stateName with a custom StateType. Returns false if it fails."}]

[{"index":"boolean ChangeState(string stateName)","0":"Forces the current state to be changed to the specified state."}]

[{"index":"void RemoveCondition(string stateName, string nextStateName) (Deprecated)","0":"Disconnects the state stateName from the state nextStateName."}]

[{"index":"void RemoveState(string name)","0":"Removes the specified state."}]

##### inherited from Component:

[{"index":"boolean IsClient()","0":"Returns whether the current execution environment is a client or not."}]

[{"index":"boolean IsServer()","0":"Returns whether the current execution environment is a server or not."}]

# Events

[{"index":"DeadEvent","0":"This event is fired when the target dies. Occurs when transitioning from State to DEAD state."}]

[{"index":"ReviveEvent","0":"This event is fired when the target is revived."}]

[{"index":"StateChangeEvent","0":"Occurs when changing state."}]

# Examples

This component displays the current state of the entity through ChatBalloon.
    
    
    @Component
    script StateChatDisplay extends Component
        @ExecSpace("ServerOnly")
        method void OnBeginPlay()
        local state = self.Entity.StateComponent
        if state == nil then
        	state = self.Entity:AddComponent("StateComponent")
        end
    
        local chatBallon = self.Entity.ChatBalloonComponent
        if chatBallon == nil then
        	chatBallon = self.Entity:AddComponent("ChatBalloonComponent")
        end
    
        self.Entity.ChatBalloonComponent.AutoShowEnabled = true
        self.Entity.ChatBalloonComponent.ChatModeEnabled = false
        self.Entity.ChatBalloonComponent.ShowDuration = 1
        self.Entity.ChatBalloonComponent.HideDuration = 0
        self.Entity.ChatBalloonComponent.FontSize = 2
        end
    
        @ExecSpace("ServerOnly")
        method void OnUpdate(number delta)
        self.Entity.ChatBalloonComponent.Message = self.Entity.StateComponent.CurrentStateName
        end
    end
    

# SeeAlso

  * ChatBalloonComponent
  * StateAnimationComponent
  * Entity
  * [Controlling Entity Status](/docs?postId=686)