How to get and set a singelton variable with visual scripting?

-Mist--Mist- Posts: 3Member
edited January 2020 in Programming


I'm a Godot newbie and I try to do a simple game. I've made a player in a separate scene with a visaul script that controls the player. Then I put this scene in my main scene and the controls works just fine... but now I want to control another object from another scene from the player script. I tried signals but that didn't work and now I trying to use a singelton variable that I can change the value of, but that was not as simple as I thought. I must be missing something, how on earth are you accessing the singelton variable from visual scripting?

Tags :


  • -Mist--Mist- Posts: 3Member

    Answer my own question here. :)
    After a long time wrestling with visual scripting in Godot I found a way to get and set singleton variables.

    How to get a singelton variable value from visual scripting. See attached image.

  • -Mist--Mist- Posts: 3Member

    And this is the nodes to set a singleton value.

  • cyberealitycybereality Posts: 5,341Moderator

    Great job. Thanks for following up with the solution.

  • ZemuneloZemunelo Posts: 4Member

    I believe for last set/get blocks you can just use: get or set and change call mode in the inspector to instance.
    Like this (GLOBALS is obviously singleton here):

    You can easily search for those. Just right click on empty and type "set(" or "get(" and you'll find them.
    Full codes in search are: Set(String, Var) & Get(String).

    You don't have to use singleton to access and change variables, you can do it in any scene script that is present on live (remote) main scene (use real path from remote) or you can preload-instantiate scene that is not there yet.

    You can also use "propagate_call()" in search: Propagate Call(String, Array, Bool), to start/call any remote function but it has to be on a script attached to scene. As far as I know for now you can't call function from alone script (not attached to some scene).

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file