FiniteStateMachine icon indicating copy to clipboard operation
FiniteStateMachine copied to clipboard

FSM transitions seems not to have access to a singleton

Open salvob41 opened this issue 6 years ago • 5 comments

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 avatar Mar 30 '18 14:03 salvob41

@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");

kubecz3k avatar Mar 30 '18 14:03 kubecz3k

but it's weird... How can I access it through the States node? Are they not tool scripts?

salvob41 avatar Mar 30 '18 14:03 salvob41

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

kubecz3k avatar Mar 30 '18 15:03 kubecz3k

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.

salvob41 avatar Mar 30 '18 15:03 salvob41

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)

kubecz3k avatar Mar 30 '18 23:03 kubecz3k