0 votes

So I set my player script to a global script and I'm trying reference "currentDir" on the player so I can set the direction for the projectiles to shoot. Except I don't know how to call it. Everything I try doesn't work but I feel like i'm really close.

The projectle (PIZZA BOX) is in another scene btw) I've also shortened down my code to just the necessities for THE PROBLEM OF CALLING ANOTHER VARIABLE FROM ANOTHER NODE IN ANOTHER SCENE

-- Player Script --
using Godot;
using System;

public class Player : KinematicBody2D
PackedScene pizzaBoxScene;

public int currentDir = 1;
float speed = 65;

public override void _Ready()
    pizzaBoxScene = GD.Load<PackedScene>("res://scenes/PizzaBox.tscn"); 

public override void _Process(float delta)

    float totalAmount = speed * delta;


    bool moveUp = Input.IsKeyPressed((int)KeyList.W) ? true : false;
    bool moveDown = Input.IsKeyPressed((int)KeyList.S) ? true : false;
    bool moveLeft = Input.IsKeyPressed((int)KeyList.A) ? true : false; 
    bool moveRight = Input.IsKeyPressed((int)KeyList.D) ? true : false;

    int up = 0;
    int down = 1;
    int left = 2;
    int right = 3;

    Vector2 move = new Vector2(0,0);

    // Move Up
    if (moveUp == true)
        move.y = -1;
        ((AnimationPlayer)GetNode("AnimationPlayer")).Play("Walk Up");
        currentDir = up;    // DIRECTION SET BASED ON INPUT 

    if (currentDir == 0 && moveUp == false)
        ((AnimationPlayer)GetNode("AnimationPlayer")).Play("Idle Up");


-- Projectile Script --
using Godot;
using System;

public class PizzaBox : Node2D
PackedScene GameScene;

public override void _Ready()
    GameScene = GD.Load<PackedScene>("res://Game.tscn");    

    Player.Call("_Process", currentDir);  


public override void _Process(float delta)

           // Right here is just a bunch of code for it to move but its usless if I can't control the direction 
            it spawns  in


Godot version 3.4.2
in Engine by (14 points)

1 Answer

+1 vote

About the question itself, autoload nodes are just nodes under the root of the scene tree, which are siblings of the current scene.


In GDScript, Autoload1 and Autoload2 are accessible by typing their name like a global variable as syntactic sugar. But that isn't available in other languages.

So in C#, you may access these nodes the classic way, knowing what they actually are:

var node = GetNode<TypeOfTheNode>("/root/Autoload1")
by (29,046 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.