mteb/FreshStackRetrieval huggingface dataset:
I have just started learning Godot and already know a decent bit of C# from unity. I am trying to set up a 3D character rig. The function should be there as the docs all say it should but when I compile this code:
using Godot;
using System;

public partial class world_control : Node
{
    SceneTree tree;
    Node3D camera;
    Node3D head;
    
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        tree = GetTree();
        camera = tree.get_current_scene().find_child("camera", false, false);
        head = tree.get_current_scene().find_child("head", true, false);
    }

    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _Process(double delta)
    {
        camera.set_global_position(head.get_global_position());
        camera.set_global_rotation(head.get_global_rotation());
    }
}

It gives me these errors:
/***/Godot/Hand_Cannon/world_control.cs(14,17): 'SceneTree' does not contain a definition for 'get_current_scene' and no accessible extension method 'get_current_scene' accepting a first argument of type 'SceneTree' could be found (are you missing a using directive or an assembly reference?)

/***/Godot/Hand_Cannon/world_control.cs(21,35): 'Node3D' does not contain a definition for 'get_global_position' and no accessible extension method 'get_global_position' accepting a first argument of type 'Node3D' could be found (are you missing a using directive or an assembly reference?)

(I have left out a few more errors but basically all of the functions cause this excact error)
Extra Information:
Godot 4.1 with C#
.NET 8 (Installed on day of posting)
Mac OSX 13.5.1
I can and am very willing to provide more info if needed!
This is a problem in which I simply don't know what to try. I am very new to Godot having installing it today. Nothing so far has worked, in fact I did not even know that the values had getter functions!
Hey I try to get JSON DATA. The code is below. I tried many things, but I am not able to receive a normal JSON.
func makeLoginRequest():

    var url = "https://chocolatefactory-api.dreamstudio.my/login"
    

    var data = {
        "username": "test0001",
        "password": "test0001"
    }
    

    var http_request = HTTPRequest.new()
    

    add_child(http_request)
    

    http_request.connect("request_completed",Callable(self,"_on_request_completed"))
    

    http_request.request(url, ["Content-Type: application/json"], HTTPClient.METHOD_POST, JSON.new().stringify(data))
    

func _on_request_completed(result, response_code, headers, body):

    if response_code == 200:

        print("Anfrage erfolgreich!!")
        var json_data = JSON.new().parse(str(body))
    
            
    else:
        print("Fehler bei der Anfrage. Fehlercode:", response_code)

I always get this:
[123, 10, 32, 32, 34, 116, 111, 107, 101, 110, 34, 58, 32, 34, 101, 121, 74, 104, 98, 71, 99, 105, 79, 105, 74, 73, 85, 122, 73, 49, 78, 105, 73, 115, 73, 110, 82, 53, 99, 67, 73, 54, 73, 107, 112, 88, 86, 67, 74, 57, 46, 101, 121, 74, 49, 99, 50, 86, 121, 83, 87, 81, 105, 79, 105, 73, 49, 90, 71, 82, 108, 77, 68, 65, 119, 77, 106, 100, 108, 89, 87, 77, 48, 90, 68, 77, 120, 79, 71, 81, 53, 78, 106, 103, 51, 90, 87, 85, 53, 89, 87, 74, 108, 77, 122, 107, 48, 77, 105, 73, 115, 73, 110, 86, 122, 90, 88, 74, 117, 89, 87, 49, 108, 73, 106, 111, 105, 100, 71, 86, 122, 100, 68, 65, 119, 77, 68, 69, 105, 76, 67, 74, 108, 101, 72, 65, 105, 79, 106, 69, 51, 77, 68, 77, 50, 78, 122, 89, 50, 77, 106, 82, 57, 46, 102, 73, 52, 74, 55, 53, 82, 106, 88, 74, 51, 77, 122, 66, 117, 121, 66, 90, 77, 122, 98, 82, 51, 108, 81, 120, 66, 120, 54, 115, 81, 81, 48, 118, 70, 90, 114, 111, 104, 71, 110, 106, 65, 34, 44, 10, 32, 32, 34, 117, 115, 101, 114, 73, 100, 34, 58, 32, 34, 53, 100, 100, 101, 48, 48, 48, 50, 55, 101, 97, 99, 52, 100, 51, 49, 56, 100, 57, 54, 56, 55, 101, 101, 57, 97, 98, 101, 51, 57, 52, 50, 34, 44, 10, 32, 32, 34, 117, 115, 101, 114, 110, 97, 109, 101, 34, 58, 32, 34, 116, 101, 115, 116, 48, 48, 48, 49, 34, 10, 125, 10]
I have a @tool-annotated empty scene which extends Node3D that I use for marking NPC spawn locations. On ready when is_editor_hint I add a mesh instance with geometry so the location is visible in the editor. The added mesh gets displayed in the editor just fine and everything works as expected except that clicking the tool-created mesh (which is child of the instantiated scene) in the editor doesn't actually select the parent scene. If I add the very same mesh to the scene statically instead of on _ready, I can select the instantiated scene by clicking the mesh as I would expect.
Is there any way to make this "dynamically created child" clickable in the editor? Is there anything that the editor sets when adding a child node that doesn't happen when using add_child? I've tried reparenting or changing owner but nothing helped. Also the child's AABBs are correct.
For reference the Node3D scene's script goes like this:
func _ready() -> void:
    if Engine.is_editor_hint():
        var mesh_instance = MeshInstance3D.new()
        mesh_instance.position.y += 0.03
        mesh_instance.cast_shadow = false
        var qmesh: QuadMesh = QuadMesh.new()
        qmesh.size = Vector2(0.4, 0.4)
        mesh_instance.mesh = qmesh
        add_child(mesh_instance)

Thank you for any help, trying to find specific spawner in the tree can be really frustrating.
EDIT:
Solved by the issue linked in Bugfish' comment: Setting owner to self in the tool script makes it work as expected. The owner needs to be set AFTER the child is added.
add_child(mesh)
mesh.owner = self

seems to work, while
mesh.owner = self
add_child(mesh)

does not
When using ResourceLoader's .load_threaded_request, .load_threaded_get_status and .load_threaded_get I can't get a loaded resource a second time. I expected it to be cached and now I'm unsure if that is the intended functionality.
I am using Godot 4.2 on MacOS (Intel) and exploring asynchronous resource loading functionality. Here's a snippet showing some of my code:
const ROCKET_SCENE_FILE: String = "res://scenes/rocket.tscn"


func _ready():
    ResourceLoader.load_threaded_request(ROCKET_SCENE_FILE) # asynchronously load the rocket scene


func fire_rocket() -> void:
    var rocket_loading_status: ResourceLoader.ThreadLoadStatus = ResourceLoader.load_threaded_get_status(ROCKET_SCENE_FILE)
    if  rocket_loading_status == ResourceLoader.THREAD_LOAD_LOADED:
        var rocket_scene: Resource = ResourceLoader.load_threaded_get(ROCKET_SCENE_FILE) # get the loaded scene
        var rocket_instance: Node = rocket_scene.instantiate() # instance the scene
        add_child(rocket_instance) # add to this scene
    else:
        assert(rocket_loading_status == ResourceLoader.THREAD_LOAD_IN_PROGRESS, "FAULT failure loading rocket resource: ResourceLoader.ThreadLoadStatus = " + str(rocket_loading_status))


func _process(delta: float) -> void:
    if handle_actions:
        process_actions() # read input and set state/triggers
    
    if shoot == true:
        fire_rocket()
        shoot = false # reset the shoot trigger

The first time fire_rocket executes everything works as I expected: the status is THREAD_LOAD_LOADED and I successfully get the resource from the ResourceLoader. Strangely, the second time the status is THREAD_LOAD_INVALID_RESOURCE - meaning, The resource is invalid, or has not been loaded with load_threaded_request.
I thought that ResourceLoader would cache the loaded resource since the default cache mode for ResourceLoader.load_threaded_request is CACHE_MODE_REUSE. There's no explanation of what the cache modes mean, in the documentation, so I'm not certain if this is a bug or my misinterpretation. Also my C++ knowledge is so old that I don't really understand what's going on in the source code - so looking at that wasn't really helpful for me.
Does anyone know if ResourceLoader is intended to cache resources so that they can be retrieved multiple times, or if it is a one time retrieval only?
I can create the code and logic, and it works fine. However, the problem arises when my camera goes out of the range of the Node2d node; it loses control of the Camera2D controls, and I never expected this issue in Godot.
I highly recommend you watch this video as it can provide you with a better understanding of the issue.
Download link: https://firebasestorage.googleapis.com/v0/b/alor28.appspot.com/o/uploads%2FScreencast%202023-12-31%2018%3A02%3A34.mp4?alt=media&token=16769086-c2e0-494b-8336-d670468aa0f3
i want to fix this zoom issue i don't want this types of issue i don't think it come with my Camera controller script.
also here is my code if need
extends Camera2D

# Player reference
var player

# Camera settings
var default_zoom = Vector2(0.4, 0.4)   # Default zoom level
var camera_offset = Vector2(0, 0)      # Offset between player and camera
var follow_speed = 0.7                 # Speed of camera following
var zoom_speed = 0.2                   # Speed of zooming while moving
var zoom_step = 0.1                    # Zoom step when moving or jumping

# Track player's previous position to determine movement
var prev_player_position = Vector2.ZERO

func _ready():
    # Attempt to find the player node dynamically with a maximum number of attempts
    var max_attempts = 10
    var current_attempt = 0

    while player == null and current_attempt < max_attempts:
        player = get_node_or_null("/root/Game/Player")
        current_attempt += 1

        if player == null:
            print("Player node not found. Retrying in 1 second...")
            yield(get_tree().create_timer(1.0), "timeout")

    if player == null:
        print("Player node not found after multiple attempts.")

    # Set the initial zoom to the default value
    set_zoom(default_zoom)


func _process(_delta):
    # Rest of the code remains unchanged
    if player:
        var target_pos = player.global_position + camera_offset
        position = position.linear_interpolate(target_pos, follow_speed)
        clamp_to_scene_bounds()
        apply_zoom_step()


func clamp_to_scene_bounds():
    # Optionally, you can add code here to clamp the camera position to the scene bounds
    # For example:
    var viewport_rect = get_viewport_rect()
    position.x = clamp(position.x, viewport_rect.position.x, viewport_rect.size.x)
    position.y = clamp(position.y, viewport_rect.position.y, viewport_rect.size.y)

func apply_zoom_step():
    if player.global_position != prev_player_position:
        # Player is moving or jumping
        var distance_to_player = position.distance_to(player.position)
        var target_zoom = clamp(1.0 / (distance_to_player * zoom_speed), 0.5, 2.0)

        # Apply zoom step
        var new_zoom = Vector2(default_zoom.x * target_zoom, default_zoom.y * target_zoom)
        new_zoom = new_zoom.linear_interpolate(get_zoom(), zoom_step)
        set_zoom(new_zoom)

    # Update the previous player position for the next frame
    prev_player_position = player.global_position
I am trying to display a Node2D which contains text and animation when the player enters an interaction zone. The Node2D I am trying to display, called EToInteract, is displaying, but something is messed up with its position and movement. Here is a video of what happening. You can see that the interact display is on the top left, and its not moving. Or rather, it is static on the screen. In my Interaction Manager, I used the following code:
...
Node2D interactDisplay;

public override void _Ready()
{
    ...
    interactDisplay = GetNode<Node2D>("/root/WorldNode/InterfaceManager/EToInteract");
    interactDisplay.Hide();
    ...
}

public override void _Process(double delta)
{
    if (activeAreas.Count > 0 && canIneract)
    {
        ...
        interactDisplay.GlobalPosition = otherBody.GlobalPosition;
        interactDisplay.Show();
    }
    else
        interactDisplay.Hide();
}

otherBody is the purple NPC character you see in the video.
And this is the layout of my World Scene

I am trying to have the interact display to be on top of the NPC constantly, instead of moving around with the player like you see with the video. I though positioning the display's global position to the NPC's global position would work, but that doesn't seam to be the case. Any suggestions?
After exporting my project to Android a directory named .godot/exported appeared in the root of my Godot project. It seems to contain some cache for the resources I have exported.
Problem is, autofill gets scenes from it when I type stuff like get_tree().change_scene_to_file and it messes with my ability to find the resources I need.
Do you know if there is an option in Godot 4 which allows users to exclude specific directories from autofill?

Edit1: I am using Godot v4.1.1 under Ubuntu 22.04.3 LTS. I thought this information might be useful.
I have .godot/ directory in my .gitignore and the files from there are not tracked by git but are still popping up in the autofill for the change_scene_to_file method. I checked that preload() doesn't show resources from .godot/ directory as this Godot doc page describes but it is not my current issue.
I want to implement a double jump mechanic in Godot with C#, but it does not work as expected. Maybe someone sees a problem in my code and could give me a hint! :)
My character jumps one time and then goes straight down, instead of doing a double jump.
Appreciate the help.
using Godot;

public partial class Player : CharacterBody2D
{
private float _runSpeed = 750;
private float _jumpSpeed = -1000;
private float _gravity = 2500;
private int _jump_counter = 0;
private int _extra_jumps = 1;


public override void _PhysicsProcess(double delta)
{
    var velocity = Velocity;        
    velocity.X = 0;

    var right = Input.IsActionPressed("move_right");
    var left = Input.IsActionPressed("move_left");
    var jump = Input.IsActionPressed("move_jump");
    
    //TODO -> Implement double jump
    if (jump && _jump_counter < _extra_jumps){
        velocity.Y = _jumpSpeed;
        _jump_counter += 1;
        GD.Print(_jump_counter + " " + _extra_jumps);
    }
    
    if (right){
        velocity.X += _runSpeed;
    }
    
    if (left){
        velocity.X -= _runSpeed;
    }
    
    if (IsOnFloor()){
        _jump_counter = 0;
    }
    
    Velocity = velocity;
    
    var animatedSprite2D = GetNode<AnimatedSprite2D>("Sprite2D");

    if (velocity.Length() > 0)
    {
        velocity = velocity.Normalized() * _runSpeed;
        animatedSprite2D.Play();
    }
    else
    {
        animatedSprite2D.Stop();
    }
    
    if (velocity.X != 0)
    {
        animatedSprite2D.Animation = "walking";
        animatedSprite2D.FlipV = false;
        // See the note below about boolean assignment.
        animatedSprite2D.FlipH = velocity.X < 0;
    }
    
    velocity = Velocity;
    velocity.Y += _gravity * (float)delta;
    Velocity = velocity;
    MoveAndSlide(); 
   }
}

Thank you in advance.
Im making a game in Godot 4 and have a main world scene that the player is on. It has an Area2d node that changes the current scene to a UI scene when the player enters the area2D. The area2D takes a PackedScene and locationName as export variables. It loads the UI scene (named "Location") fine but I cannot get the UI scene to load the locationName I want. Also, the UI scene is not in the world scene (ie. where the area2d is and player are)
I have tried multiple methods including moving the UI scene to the world scene and using signals, also creating set gets. The problem seems to be coming from the fact that the label node on the UI is ready after the name is changed, so I get a nil exception.
Location.gd:
extends Node

@onready var itemList = $VBoxContainer/HBoxContainer/VBoxContainer/ItemList
@onready var nameLabel = $VBoxContainer/HBoxContainer/VBoxContainer/LocationName
@onready var image = $VBoxContainer/HBoxContainer/Image

var localName: String = "test"

func setLocationName(newName: String):
    self.localName = newName
    print(self.localName)
    
func setLocationImage(newImage: Image):
    image.texture = newImage

# Called when the node enters the scene tree for the first time.
func _ready():
    print("ready")
    if is_node_ready():
        update()
    #generate 3 rgcs and add them to itemList, display their name, gang, and favor
    #image.texture = ResourceLoader.load(location image)
    
func update():
    print("update")
    nameLabel.text = self.localName
    print(self.localName)

EntryPoint.gd:
extends Area2D

@export var targetLocation : PackedScene
@export var locationName: String

func _ready():
    pass

func _on_body_entered(body):
    var location = targetLocation.instantiate()
    location.setLocationName(locationName)
    get_tree().change_scene_to_packed(targetLocation)

    

enter image description here
I'm making a grid based 2d puzzle game where you move each character once, and then end your turn. When your turn ends, water spreads to all surounding free grids next to the current water blocks. If water enters an area inhabited by a character, the character drowns. I can get the water to spread the first round, but the created water blocks don't continue to spread
extends Area2D

signal next_turn

@onready var check_up = $CollisionShape2D/ray_up
@onready var check_down = $CollisionShape2D/ray_down
@onready var check_left = $CollisionShape2D/ray_left
@onready var check_right = $CollisionShape2D/ray_right

var water_block = ["res://water.tscn", ]
var water_block_count = 1

# Called when the node enters the scene tree for the first time.
func _ready():
    pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
    pass


func _on_hud_end_turn():
    var count = 0
    var new_water = 0
    while count != water_block_count:
        var water_scene = load(water_block[count])
        if check_up && check_down && check_left && check_right:
            water_block.remove_at(count)
            new_water -= 1
        if not check_up.is_colliding():
            var water = water_scene.instantiate()
            water.position += Vector2(0, -64)
            add_child(water)
            count += 1
            new_water += 1
            water_block[count] = get_node(water)
        if not check_down.is_colliding():
            var water = water_scene.instantiate()
            water.position += Vector2(0, 64)
            add_child(water)
            count += 1
            new_water += 1
            water_block[count] = get_node(water)
        if not check_left.is_colliding():
            var water = water_scene.instantiate()
            water.position += Vector2(-64, 0)
            add_child(water)
            count += 1
            new_water += 1
            water_block[count] = get_node(water)
        if not check_right.is_colliding():
            var water = water_scene.instantiate()
            water.position += Vector2(64, 0)
            add_child(water)
            count += 1
            new_water += 1
            water_block[count] = get_node(water)
        
    water_block_count += new_water
    next_turn.emit()

This is my current code block... it isnt working at all. I first tried to have my water be a packed scene in inself. This allowed me to instantiate the new water blocks being created. The problem was it would only check from the packed scene. This was my attempt to fix that by saving the water child node created into an array so i could call that array to create spread at that node. I also added a part in the beginning to delete nodes that are no long spreading from the array. I get "Invalid type in function 'get_node' in base 'Area2D (Water.gd)'. Cannot convert argument 1 from Object to NodePath"
I have 3 vectors, xyz, and i want to change only 1 and then calculate the other 2 in respect to their former directions (the closest possible to them). And i want to do it the most efficient way in terms of memory usage/game design.
small illustration of the problem

EDIT (after some constructive comments from Stef):
What we have:

x,y,z 3d vector, normalized and with same origin (0,0,0)
y' (the up vector changes depending on the surface)

What (i believe) we need:

z' or x' (and all mutually perpendicular)

What i tried:

z' with the help of the y - y' angle around the x-axis and vice versa with x' and the z-axis. i think this "could" work with the proper linear algebra knowledge but would still mean an euler rotation, right? i prefer to only rotate with quaternions even though i still earn to figure them out
using the cross-product of y' and x to get z' and then creating the crossproduct of z' and y' to get x'. in theory it should work? my 3 dot-product are never 0, not one of them

What i desire:

changing the x and z vector based on the angle of y and y' via a quaternion. i am working in godot and still figuring things out.. that said, i just found this:


Quaternion Quaternion ( Vector3 arc_from, Vector3 arc_to )

Constructs a quaternion representing the shortest arc between two points on the surface of a sphere with a radius of 1.0.
i made a autoload file named "saveLoad.gd"
The content of "saveLoad.gd" is:
var a = 0
var b = 1

then, i tried to acess "saveLoad.gd" file in this way:
var items = [a, b]

func store(itemname):
    if saveLoad.itemname == 0:
        itemname.visible = false

func _ready:
    store(items)

(there are a button named "a" and "b")
but it doesnt work well
i think because engine recognize saveLoad.itemname as variable in "saveLoad.gd"
not saveLoad.a or saveLoad.b
How can i make this work?
edit)
The comment code block doesn't look good, so i'll add modified code here
func store(itemname:Array):
    for i in range(0, len(itemname), +1):
        var itemname2 = itemname[i]
        if Savenload.get(itemname2) == 0:
            get(itemname2).visible = false
During getting improvement to my custom import resource plugin I faced with need of set custom (re)importing params such as: compress mode (vram compressed or etc), channel pack (optimised or RGBFriendly). But I didn't find any clues in source classes or the documentation of Godot. How can I manually import file with setting import settings precisely?
I've tried looking through various of available import-named classes (EditorImportPlugin, EditorInterface, ResourceImporterTexture), but none of them could help me in any way.
I have a scene called Planet and a script like that:
1. extends Node2D
2. 
3. @export var radius: float
4. 
5. func collide(other:Node2D):
6.      if other is Planet :
7.          if(radius > other.radius):
8.              print("I win")
9.          else:
10.             print("I loose")
11.     else:
12.         print("Not a planet")

The line 6 gives me an error Could not find type "Planet" in the current scope.
How do I do these kinds of tests where I check that a scene object is of particular type(current scene's type)?
Also, is it possible to specify a parameter type (line 5) to a particular scene? Smth like
func collide(other:Planet):

I know, it doesn't change much since the language is dynamically typed. But that would help with documentation and maybe autocomplete.