FiniteStateMachine
FiniteStateMachine copied to clipboard
FSM transitions seems not to have access to a singleton
After having instantiate a globa singleton http://docs.godotengine.org/en/stable/getting_started/step_by_step/singletons_autoload.html
this seems not be accessed by the transitions node, saying: - Compile Error: Identifier not found: global
while the States node can access them
@salvob41 yes, sorry about that, singletons/autoloads cant be used in tool scripts directly (but they still can be used if you fetch them with get_node
.
It's Godot limitation. To workaround please do something like this inside the script:
onready var global = get_node("/root/global");
but it's weird... How can I access it through the States node? Are they not tool scripts?
As I said you cant do it directly but you can use get node. (each singleton is an ordinary node that resides as a child of /root
Yes, Thank you for your reply. My comment was trying to make another point though. I'll try to explain better: When I try to access the global singleton from a State Node, I can do it. From the transition node, I cannot.
yes, States are not tool scripts, Transitions are tool scripts. You can recognize this by the first line in the script. Tool scripts are the scripts that can be used inside editor. Transitions need to be tools since they are holding connections between states and the plugin need to fetch this information to build state graph. Hope in the future it will be possible to better distinguish between 'part of the script that need to work inside editor' and 'part of the script that need to work in runtime'. For now it's not possible and that's why there are couple limitations. (from anoother sideefect of transitions beeing a tool - if there will be syntax error inside transition, the editor will be unable to compile the script and fetch needed information, so the connection will dissapear from the graph)