class_animationnodestatemachine.rst 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/4.2/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.2/doc/classes/AnimationNodeStateMachine.xml.
  6. .. _class_AnimationNodeStateMachine:
  7. AnimationNodeStateMachine
  8. =========================
  9. **Inherits:** :ref:`AnimationRootNode<class_AnimationRootNode>` **<** :ref:`AnimationNode<class_AnimationNode>` **<** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. A state machine with multiple :ref:`AnimationRootNode<class_AnimationRootNode>`\ s, used by :ref:`AnimationTree<class_AnimationTree>`.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Contains multiple :ref:`AnimationRootNode<class_AnimationRootNode>`\ s representing animation states, connected in a graph. State transitions can be configured to happen automatically or via code, using a shortest-path algorithm. Retrieve the :ref:`AnimationNodeStateMachinePlayback<class_AnimationNodeStateMachinePlayback>` object from the :ref:`AnimationTree<class_AnimationTree>` node to control it programmatically.
  15. \ **Example:**\
  16. .. tabs::
  17. .. code-tab:: gdscript
  18. var state_machine = $AnimationTree.get("parameters/playback")
  19. state_machine.travel("some_state")
  20. .. code-tab:: csharp
  21. var stateMachine = GetNode<AnimationTree>("AnimationTree").Get("parameters/playback") as AnimationNodeStateMachinePlayback;
  22. stateMachine.Travel("some_state");
  23. .. rst-class:: classref-introduction-group
  24. Tutorials
  25. ---------
  26. - :doc:`Using AnimationTree <../tutorials/animation/animation_tree>`
  27. .. rst-class:: classref-reftable-group
  28. Properties
  29. ----------
  30. .. table::
  31. :widths: auto
  32. +--------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------+
  33. | :ref:`bool<class_bool>` | :ref:`allow_transition_to_self<class_AnimationNodeStateMachine_property_allow_transition_to_self>` | ``false`` |
  34. +--------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------+
  35. | :ref:`bool<class_bool>` | :ref:`reset_ends<class_AnimationNodeStateMachine_property_reset_ends>` | ``false`` |
  36. +--------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------+
  37. | :ref:`StateMachineType<enum_AnimationNodeStateMachine_StateMachineType>` | :ref:`state_machine_type<class_AnimationNodeStateMachine_property_state_machine_type>` | ``0`` |
  38. +--------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+-----------+
  39. .. rst-class:: classref-reftable-group
  40. Methods
  41. -------
  42. .. table::
  43. :widths: auto
  44. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`add_node<class_AnimationNodeStateMachine_method_add_node>` **(** :ref:`StringName<class_StringName>` name, :ref:`AnimationNode<class_AnimationNode>` node, :ref:`Vector2<class_Vector2>` position=Vector2(0, 0) **)** |
  46. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`add_transition<class_AnimationNodeStateMachine_method_add_transition>` **(** :ref:`StringName<class_StringName>` from, :ref:`StringName<class_StringName>` to, :ref:`AnimationNodeStateMachineTransition<class_AnimationNodeStateMachineTransition>` transition **)** |
  48. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Vector2<class_Vector2>` | :ref:`get_graph_offset<class_AnimationNodeStateMachine_method_get_graph_offset>` **(** **)** |const| |
  50. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`AnimationNode<class_AnimationNode>` | :ref:`get_node<class_AnimationNodeStateMachine_method_get_node>` **(** :ref:`StringName<class_StringName>` name **)** |const| |
  52. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`StringName<class_StringName>` | :ref:`get_node_name<class_AnimationNodeStateMachine_method_get_node_name>` **(** :ref:`AnimationNode<class_AnimationNode>` node **)** |const| |
  54. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`Vector2<class_Vector2>` | :ref:`get_node_position<class_AnimationNodeStateMachine_method_get_node_position>` **(** :ref:`StringName<class_StringName>` name **)** |const| |
  56. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`AnimationNodeStateMachineTransition<class_AnimationNodeStateMachineTransition>` | :ref:`get_transition<class_AnimationNodeStateMachine_method_get_transition>` **(** :ref:`int<class_int>` idx **)** |const| |
  58. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`int<class_int>` | :ref:`get_transition_count<class_AnimationNodeStateMachine_method_get_transition_count>` **(** **)** |const| |
  60. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`StringName<class_StringName>` | :ref:`get_transition_from<class_AnimationNodeStateMachine_method_get_transition_from>` **(** :ref:`int<class_int>` idx **)** |const| |
  62. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`StringName<class_StringName>` | :ref:`get_transition_to<class_AnimationNodeStateMachine_method_get_transition_to>` **(** :ref:`int<class_int>` idx **)** |const| |
  64. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`bool<class_bool>` | :ref:`has_node<class_AnimationNodeStateMachine_method_has_node>` **(** :ref:`StringName<class_StringName>` name **)** |const| |
  66. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`bool<class_bool>` | :ref:`has_transition<class_AnimationNodeStateMachine_method_has_transition>` **(** :ref:`StringName<class_StringName>` from, :ref:`StringName<class_StringName>` to **)** |const| |
  68. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`remove_node<class_AnimationNodeStateMachine_method_remove_node>` **(** :ref:`StringName<class_StringName>` name **)** |
  70. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`remove_transition<class_AnimationNodeStateMachine_method_remove_transition>` **(** :ref:`StringName<class_StringName>` from, :ref:`StringName<class_StringName>` to **)** |
  72. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | void | :ref:`remove_transition_by_index<class_AnimationNodeStateMachine_method_remove_transition_by_index>` **(** :ref:`int<class_int>` idx **)** |
  74. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`rename_node<class_AnimationNodeStateMachine_method_rename_node>` **(** :ref:`StringName<class_StringName>` name, :ref:`StringName<class_StringName>` new_name **)** |
  76. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | void | :ref:`replace_node<class_AnimationNodeStateMachine_method_replace_node>` **(** :ref:`StringName<class_StringName>` name, :ref:`AnimationNode<class_AnimationNode>` node **)** |
  78. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | void | :ref:`set_graph_offset<class_AnimationNodeStateMachine_method_set_graph_offset>` **(** :ref:`Vector2<class_Vector2>` offset **)** |
  80. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | void | :ref:`set_node_position<class_AnimationNodeStateMachine_method_set_node_position>` **(** :ref:`StringName<class_StringName>` name, :ref:`Vector2<class_Vector2>` position **)** |
  82. +---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. .. rst-class:: classref-section-separator
  84. ----
  85. .. rst-class:: classref-descriptions-group
  86. Enumerations
  87. ------------
  88. .. _enum_AnimationNodeStateMachine_StateMachineType:
  89. .. rst-class:: classref-enumeration
  90. enum **StateMachineType**:
  91. .. _class_AnimationNodeStateMachine_constant_STATE_MACHINE_TYPE_ROOT:
  92. .. rst-class:: classref-enumeration-constant
  93. :ref:`StateMachineType<enum_AnimationNodeStateMachine_StateMachineType>` **STATE_MACHINE_TYPE_ROOT** = ``0``
  94. Seeking to the beginning is treated as playing from the start state. Transition to the end state is treated as exiting the state machine.
  95. .. _class_AnimationNodeStateMachine_constant_STATE_MACHINE_TYPE_NESTED:
  96. .. rst-class:: classref-enumeration-constant
  97. :ref:`StateMachineType<enum_AnimationNodeStateMachine_StateMachineType>` **STATE_MACHINE_TYPE_NESTED** = ``1``
  98. Seeking to the beginning is treated as seeking to the beginning of the animation in the current state. Transition to the end state, or the absence of transitions in each state, is treated as exiting the state machine.
  99. .. _class_AnimationNodeStateMachine_constant_STATE_MACHINE_TYPE_GROUPED:
  100. .. rst-class:: classref-enumeration-constant
  101. :ref:`StateMachineType<enum_AnimationNodeStateMachine_StateMachineType>` **STATE_MACHINE_TYPE_GROUPED** = ``2``
  102. This is a grouped state machine that can be controlled from a parent state machine. It does not work independently. There must be a state machine with :ref:`state_machine_type<class_AnimationNodeStateMachine_property_state_machine_type>` of :ref:`STATE_MACHINE_TYPE_ROOT<class_AnimationNodeStateMachine_constant_STATE_MACHINE_TYPE_ROOT>` or :ref:`STATE_MACHINE_TYPE_NESTED<class_AnimationNodeStateMachine_constant_STATE_MACHINE_TYPE_NESTED>` in the parent or ancestor.
  103. .. rst-class:: classref-section-separator
  104. ----
  105. .. rst-class:: classref-descriptions-group
  106. Property Descriptions
  107. ---------------------
  108. .. _class_AnimationNodeStateMachine_property_allow_transition_to_self:
  109. .. rst-class:: classref-property
  110. :ref:`bool<class_bool>` **allow_transition_to_self** = ``false``
  111. .. rst-class:: classref-property-setget
  112. - void **set_allow_transition_to_self** **(** :ref:`bool<class_bool>` value **)**
  113. - :ref:`bool<class_bool>` **is_allow_transition_to_self** **(** **)**
  114. If ``true``, allows teleport to the self state with :ref:`AnimationNodeStateMachinePlayback.travel<class_AnimationNodeStateMachinePlayback_method_travel>`. When the reset option is enabled in :ref:`AnimationNodeStateMachinePlayback.travel<class_AnimationNodeStateMachinePlayback_method_travel>`, the animation is restarted. If ``false``, nothing happens on the teleportation to the self state.
  115. .. rst-class:: classref-item-separator
  116. ----
  117. .. _class_AnimationNodeStateMachine_property_reset_ends:
  118. .. rst-class:: classref-property
  119. :ref:`bool<class_bool>` **reset_ends** = ``false``
  120. .. rst-class:: classref-property-setget
  121. - void **set_reset_ends** **(** :ref:`bool<class_bool>` value **)**
  122. - :ref:`bool<class_bool>` **are_ends_reset** **(** **)**
  123. If ``true``, treat the cross-fade to the start and end nodes as a blend with the RESET animation.
  124. In most cases, when additional cross-fades are performed in the parent :ref:`AnimationNode<class_AnimationNode>` of the state machine, setting this property to ``false`` and matching the cross-fade time of the parent :ref:`AnimationNode<class_AnimationNode>` and the state machine's start node and end node gives good results.
  125. .. rst-class:: classref-item-separator
  126. ----
  127. .. _class_AnimationNodeStateMachine_property_state_machine_type:
  128. .. rst-class:: classref-property
  129. :ref:`StateMachineType<enum_AnimationNodeStateMachine_StateMachineType>` **state_machine_type** = ``0``
  130. .. rst-class:: classref-property-setget
  131. - void **set_state_machine_type** **(** :ref:`StateMachineType<enum_AnimationNodeStateMachine_StateMachineType>` value **)**
  132. - :ref:`StateMachineType<enum_AnimationNodeStateMachine_StateMachineType>` **get_state_machine_type** **(** **)**
  133. This property can define the process of transitions for different use cases. See also :ref:`StateMachineType<enum_AnimationNodeStateMachine_StateMachineType>`.
  134. .. rst-class:: classref-section-separator
  135. ----
  136. .. rst-class:: classref-descriptions-group
  137. Method Descriptions
  138. -------------------
  139. .. _class_AnimationNodeStateMachine_method_add_node:
  140. .. rst-class:: classref-method
  141. void **add_node** **(** :ref:`StringName<class_StringName>` name, :ref:`AnimationNode<class_AnimationNode>` node, :ref:`Vector2<class_Vector2>` position=Vector2(0, 0) **)**
  142. Adds a new animation node to the graph. The ``position`` is used for display in the editor.
  143. .. rst-class:: classref-item-separator
  144. ----
  145. .. _class_AnimationNodeStateMachine_method_add_transition:
  146. .. rst-class:: classref-method
  147. void **add_transition** **(** :ref:`StringName<class_StringName>` from, :ref:`StringName<class_StringName>` to, :ref:`AnimationNodeStateMachineTransition<class_AnimationNodeStateMachineTransition>` transition **)**
  148. Adds a transition between the given animation nodes.
  149. .. rst-class:: classref-item-separator
  150. ----
  151. .. _class_AnimationNodeStateMachine_method_get_graph_offset:
  152. .. rst-class:: classref-method
  153. :ref:`Vector2<class_Vector2>` **get_graph_offset** **(** **)** |const|
  154. Returns the draw offset of the graph. Used for display in the editor.
  155. .. rst-class:: classref-item-separator
  156. ----
  157. .. _class_AnimationNodeStateMachine_method_get_node:
  158. .. rst-class:: classref-method
  159. :ref:`AnimationNode<class_AnimationNode>` **get_node** **(** :ref:`StringName<class_StringName>` name **)** |const|
  160. Returns the animation node with the given name.
  161. .. rst-class:: classref-item-separator
  162. ----
  163. .. _class_AnimationNodeStateMachine_method_get_node_name:
  164. .. rst-class:: classref-method
  165. :ref:`StringName<class_StringName>` **get_node_name** **(** :ref:`AnimationNode<class_AnimationNode>` node **)** |const|
  166. Returns the given animation node's name.
  167. .. rst-class:: classref-item-separator
  168. ----
  169. .. _class_AnimationNodeStateMachine_method_get_node_position:
  170. .. rst-class:: classref-method
  171. :ref:`Vector2<class_Vector2>` **get_node_position** **(** :ref:`StringName<class_StringName>` name **)** |const|
  172. Returns the given animation node's coordinates. Used for display in the editor.
  173. .. rst-class:: classref-item-separator
  174. ----
  175. .. _class_AnimationNodeStateMachine_method_get_transition:
  176. .. rst-class:: classref-method
  177. :ref:`AnimationNodeStateMachineTransition<class_AnimationNodeStateMachineTransition>` **get_transition** **(** :ref:`int<class_int>` idx **)** |const|
  178. Returns the given transition.
  179. .. rst-class:: classref-item-separator
  180. ----
  181. .. _class_AnimationNodeStateMachine_method_get_transition_count:
  182. .. rst-class:: classref-method
  183. :ref:`int<class_int>` **get_transition_count** **(** **)** |const|
  184. Returns the number of connections in the graph.
  185. .. rst-class:: classref-item-separator
  186. ----
  187. .. _class_AnimationNodeStateMachine_method_get_transition_from:
  188. .. rst-class:: classref-method
  189. :ref:`StringName<class_StringName>` **get_transition_from** **(** :ref:`int<class_int>` idx **)** |const|
  190. Returns the given transition's start node.
  191. .. rst-class:: classref-item-separator
  192. ----
  193. .. _class_AnimationNodeStateMachine_method_get_transition_to:
  194. .. rst-class:: classref-method
  195. :ref:`StringName<class_StringName>` **get_transition_to** **(** :ref:`int<class_int>` idx **)** |const|
  196. Returns the given transition's end node.
  197. .. rst-class:: classref-item-separator
  198. ----
  199. .. _class_AnimationNodeStateMachine_method_has_node:
  200. .. rst-class:: classref-method
  201. :ref:`bool<class_bool>` **has_node** **(** :ref:`StringName<class_StringName>` name **)** |const|
  202. Returns ``true`` if the graph contains the given animation node.
  203. .. rst-class:: classref-item-separator
  204. ----
  205. .. _class_AnimationNodeStateMachine_method_has_transition:
  206. .. rst-class:: classref-method
  207. :ref:`bool<class_bool>` **has_transition** **(** :ref:`StringName<class_StringName>` from, :ref:`StringName<class_StringName>` to **)** |const|
  208. Returns ``true`` if there is a transition between the given animation nodes.
  209. .. rst-class:: classref-item-separator
  210. ----
  211. .. _class_AnimationNodeStateMachine_method_remove_node:
  212. .. rst-class:: classref-method
  213. void **remove_node** **(** :ref:`StringName<class_StringName>` name **)**
  214. Deletes the given animation node from the graph.
  215. .. rst-class:: classref-item-separator
  216. ----
  217. .. _class_AnimationNodeStateMachine_method_remove_transition:
  218. .. rst-class:: classref-method
  219. void **remove_transition** **(** :ref:`StringName<class_StringName>` from, :ref:`StringName<class_StringName>` to **)**
  220. Deletes the transition between the two specified animation nodes.
  221. .. rst-class:: classref-item-separator
  222. ----
  223. .. _class_AnimationNodeStateMachine_method_remove_transition_by_index:
  224. .. rst-class:: classref-method
  225. void **remove_transition_by_index** **(** :ref:`int<class_int>` idx **)**
  226. Deletes the given transition by index.
  227. .. rst-class:: classref-item-separator
  228. ----
  229. .. _class_AnimationNodeStateMachine_method_rename_node:
  230. .. rst-class:: classref-method
  231. void **rename_node** **(** :ref:`StringName<class_StringName>` name, :ref:`StringName<class_StringName>` new_name **)**
  232. Renames the given animation node.
  233. .. rst-class:: classref-item-separator
  234. ----
  235. .. _class_AnimationNodeStateMachine_method_replace_node:
  236. .. rst-class:: classref-method
  237. void **replace_node** **(** :ref:`StringName<class_StringName>` name, :ref:`AnimationNode<class_AnimationNode>` node **)**
  238. .. container:: contribute
  239. There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  240. .. rst-class:: classref-item-separator
  241. ----
  242. .. _class_AnimationNodeStateMachine_method_set_graph_offset:
  243. .. rst-class:: classref-method
  244. void **set_graph_offset** **(** :ref:`Vector2<class_Vector2>` offset **)**
  245. Sets the draw offset of the graph. Used for display in the editor.
  246. .. rst-class:: classref-item-separator
  247. ----
  248. .. _class_AnimationNodeStateMachine_method_set_node_position:
  249. .. rst-class:: classref-method
  250. void **set_node_position** **(** :ref:`StringName<class_StringName>` name, :ref:`Vector2<class_Vector2>` position **)**
  251. Sets the animation node's coordinates. Used for display in the editor.
  252. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  253. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  254. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  255. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  256. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  257. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  258. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`