mteb/FreshStackRetrieval huggingface dataset:
I'm working on porting a unity project that I made a while ago over to Godot.
In Unity I have a class that looks like this:
public class MeshGenerator 
{

    public SquareGrid squareGrid;
    public MeshFilter walls;

    void CreateWallMesh(int[,] map, float squareSize, int tileAmount){
        MeshCollider currentColliders = walls.gameObject.GetComponent<MeshCollider>();
        Destroy(currentColliders);
        CalculateMeshOutlines();

        List<Vector3> wallVertices = new List<Vector3>();
        List<int> wallTriangles = new List<int>();
        Mesh wallMesh = new Mesh();
        float wallHeight = 5;

        foreach(List<int> outline in outlines){
            for(int i = 0; i < outline.Count-1; i++){
                int startIndex = wallVertices.Count;
                wallVertices.Add(vertices[outline[i]]); // left vertex
                wallVertices.Add(vertices[outline[i+1]]); // right vertex
                wallVertices.Add(vertices[outline[i]] - Vector3.up * wallHeight); // bottom left vertex
                wallVertices.Add(vertices[outline[i+1]] - Vector3.up * wallHeight); // bottom right vertex

                wallTriangles.Add(startIndex + 0);
                wallTriangles.Add(startIndex + 2);
                wallTriangles.Add(startIndex + 3);

                wallTriangles.Add(startIndex + 3);
                wallTriangles.Add(startIndex + 1);
                wallTriangles.Add(startIndex + 0);
            }
        }
        wallMesh.vertices = wallVertices.ToArray();
        wallMesh.triangles = wallTriangles.ToArray();

        MeshCollider wallCollider = walls.gameObject.AddComponent<MeshCollider>();
        wallCollider.sharedMesh = wallMesh;

        float textureScale = walls.gameObject.GetComponentInChildren<MeshRenderer> ().material.mainTextureScale.x;
        float increment = (textureScale / map.GetLength(0));
        Vector2[] uvs = new Vector2[wallMesh.vertices.Length];
        float[] uvEntries = new float[]{0.5f,increment}; 

        for (int i = 0; i < wallMesh.vertices.Length; i++) 
        {
            float percentY = Mathf.InverseLerp ((-wallHeight) * squareSize, 0, wallMesh.vertices [i].y) * tileAmount * (wallHeight / map.GetLength(0));
            uvs [i] = new Vector2(uvEntries[i % 2],percentY);
        }

        wallMesh.uv = uvs;
        wallCollider.sharedMesh = wallMesh;
        walls.mesh = wallMesh;
    }

And I'm getting an error that says

The type or namespace name 'MeshFilter' could not be found (are you
missing a using directive or an assembly reference?)

I believe it's referencing this unity mesh, and I'm curious what the correct way to do it in Godot is.

Edit:
In case it helps, what the class does is takes a random 2D map and builds up walls around the area the player is supposed to travel through. Here's a sample:
Camera or other nonmoving objects does not look like teleporting when moving the camera with damping. Player does not look like teleporting when camera is stationary. Player does not look like teleporting when camera follows player without damping. But when camera is set to follow player with damping, player looks like teleporting (other nonmoving objects still appear normal).
Code at the camera
func _process(delta):
    #Smooth transition
    var to = character.position + origin
    camPosWoutOffset = smoothTo(camPosWoutOffset, to, smoothness, delta)

    #offset added to smoothed position
    self.global_transform.origin = Vector3(camPosWoutOffset.x + offset.x,
    origin.y + offset.y, camPosWoutOffset.z + offset.z)

func smoothTo(from: Vector3, to: Vector3, smoothness: float, delta: float) -> Vector3:
    var output = Vector3(damp(from.x, to.x, smoothness, delta),
    to.y, damp(from.z, to.z, smoothness, delta))
    return output

func damp(source: float, target: float, smoothing: float, delta: float) -> float:
    return lerp(source, target, 1 - pow(smoothing, delta))

Code at the player
    accel = axis * 150 * delta
    velocity += accel
    velocity = velocity.limit_length(MaxSpeed)
    move_and_slide()

How it looks:
https://youtu.be/s1cYYLDoNk8
https://www.youtube.com/watch?v=s1cYYLDoNk8
I have tried lerp, slerp both with and without "delta time" but all had problems.
I am trying to use the BodyShapeEntered signal for an Area3D in C#. I can't figure out what the delegate should look like for this event.
I get the following compile error: "No overload for 'OnCollision' matches delegate 'Area3D.BodyShapeEnteredEventHandler'"
Unfortunately, I can't find any info about what parameters I should use for this handler, if this isn't it. My code matches the description in https://docs.godotengine.org/en/4.2/classes/class_area3d.html#signals
I am using version 4.2. Here is my code:
using Godot;
using System;

public partial class LocationExit : Area3D
{
    public static readonly PackedScene DefaultExitScene = ResourceLoader.Load<PackedScene>("res://Overworld/Overworld.tscn");
    
    public PackedScene ExitScene;//alternate scene to exit to
    string StoryVariableOnExit;//increments this variable in the story on collision
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        this.BodyShapeEntered += OnCollision;
    }

    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _Process(double delta)
    {
    }
    
    
    private void OnCollision(Rid body_rid, Node3D body, int body_shape_index, int local_shape_index)
    {
        //cannot use, this will not compile
    }
}
I can't find a structure representing a file in Godot to use in the editor
I want to add a property to my Node
something like:
[GlobalClass]
public partial class MyObj : Node2D
{
    [Export] public File myFile;

...

It should be possible to pick a file (a file location) and assign it to that variable, is it possible?
I tried following Godot's documentation on MultiMeshes (the set_instance_color is specially interesting), but my models always end up washed out, way brighter than they should be (left is the correct model, right is after multimeshes applied):

It's a model made out of voxels. Each cube is put into the same multimesh and then each instance's color is changed depending on the imported model's colors.
In the Godot engine, it is possible to define one scene as the "main scene". In the tutorials provided in the docs, the "main scene" is simply the scene your game starts with, and that is also the description I can find in various places.
Yet, it is not yet clear to me which one of the following is true about the "main scene", or whether actually both are possible and it is just an implementation decision:

The main scene is the first scene displyed when the game starts. In more complex games, it will be replaced once or multiple times throughout the run of the game.
The main scene is the root scene filling the screen throughout the game's lifetime. Thus, it contains just e.g. a title bar and a large subview or something. Whenever the "screen" (whatever the user sees, e.g. a full-screen main menu vs. the actual in-game screen) switches, the content of the subview changes.

Is it the former, the latter, or both, depending on what I decide during implementation?
I created this topic so I could ask you a question, how can I change the configuration of a Godot project through code. What happens is that I want to create a configuration menu for my project, which would be to change the resolution to give an example.
It sounds simple and it really is, but it turns out that most of the information is very old and is no longer compatible with Godot 4, since the majority would be for version 3.
I have tried using plugins like Godot Game Settings to make the task easier, but it turned out that it greatly reduced performance and caused many errors in its execution. Although this can be caused by many reasons not linked to the plugins.
I am making a portal system in godot 4. There are 2 worlds, everything in the normal world is on layer 1 or culling layer 1 (lights), and vice versa for altered world. The player model that moves around has two cameras, one's layer is the normal layer (the main one) and the other camera's layer is the altered layer. I have script that gets what the altered camera is seeing, and it gives that image to a shader to draw it.
gdscript:
extends MeshInstance3D

var portalTexture : Texture
var portalMaterial : ShaderMaterial
@onready var altered_camera= $"../../MainCharacter/altered_camera"


func _process(delta):
        scale = Vector3(altered_camera.get_viewport().get_texture(
).get_size().x / 1000,altered_camera.get_viewport().get_texture().get_size(
).y / 1000,.1)
get_active_material(0).set_shader_parameter("portal_texture",                                                            
altered_camera.get_viewport().get_texture())

shader code:
shader_type spatial;
uniform sampler2D portal_texture;


void fragment() {
    ALBEDO = texture(portal_texture, UV ).xyz;
}

When I look at the mesh, I see what the normal camera sees, instead of the altered one. I know this because there is a ball in front of the camera that is only in the altered world. What's going on?
I think it may be because the camera in the normal world is selected as the current one.
I am making an RTS game in godot4 4.2.1 Stable, just for shiggles. I am right clicking to perform a raycast. When I start the game and I right click, I am getting a duplicate input and it is giving me 2 seperate answers. Here is the code I am working with and its output.
if Input.is_action_just_pressed("Right_Click"):
    rayCast()
    if results.size() > 0 && ControlsMaster.selected_actors.size() > 0:
        print("RIGHT CLICKED at: ", round(results.position), "\n")
        ControlsMaster.mouse_pos_ref = round(results.position)
        ControlsMaster.formation("square", results)
        print("complete\n")
        results.clear()

func rayCast():
    var worldspace = get_world_3d().direct_space_state
    var from = project_ray_origin(mouse_POS)
    var to = project_position(mouse_POS, 1000)
    results = worldspace.intersect_ray(PhysicsRayQueryParameters3D.create(from, to))

The raycast is coming from the mouse and projecting to the map perpendicular to the screen. The ouput that I get is the following. This output is coming from a single click.
selected_actors array contains: [UNIT_0001:<CharacterBody3D#36691772857>, UNIT_0011:<CharacterBody3D#38033950217>]

RIGHT CLICKED at: (-40, 8, -6)

lead_actor_position(-40.12659, 7.526592, -6.26702)
result position(-40.12659, 7.526592, -6.26702)
{ "Position_0": (-40.12659, 7.526592, -6.26702), "Position_1": (-45.12659, 0, -6.26702), "Position_2": (-35.12659, 0, -6.26702), "Position_3": (-40.12659, 0, -1.26702), "Position_4": (-40.12659, 0, -11.26702), "Position_5": (-45.12659, 0, -1.26702), "Position_6": (-35.12659, 0, -1.26702), "Position_7": (-45.12659, 0, -11.26702), "Position_8": (-35.12659, 0, -1.26702) }
complete

RIGHT CLICKED at: (-78, 0, -107)

lead_actor_position(-78.43892, 0, -106.6246)
result position(-78.43892, 0, -106.6246)
{ "Position_0": (-78.43892, 0, -106.6246), "Position_1": (-83.43892, 0, -106.6246), "Position_2": (-73.43892, 0, -106.6246), "Position_3": (-78.43892, 0, -101.6246), "Position_4": (-78.43892, 0, -111.6246), "Position_5": (-83.43892, 0, -101.6246), "Position_6": (-73.43892, 0, -101.6246), "Position_7": (-83.43892, 0, -111.6246), "Position_8": (-73.43892, 0, -101.6246) }
complete

Im not sure how to add the 2 scripts that would make up the context, I dont come here often. Sorry in advance.
I have tried changing it to a key press or press and hold and it still does the double output.
The closer the raycast is to the center of the camera, the more accurate it is. The farther it is from 0,0,0 the further the actor spawns from where I actually did the mouse press at.
I have also tried to condition it so that it would check a variable called was_mouse_pressed. If it was false, it would allow the click, if True, then it would not allow the click. When I did this, it would run through the code, set it to True and then run the code again with it being false at the start and then turning True again. Even though I never had a code line to reset the bool to false.
I really don't understand and might switch to Unreal for the project. Unity isn't an option for me.
In Godot, using C#, I'm trying to do something that I'd assume would be super simple, but I can't seem to get it to work the way I would like.
I have struct SnapPoint that simply stores a Vector3 and a string.
public struct SnapPoint
{
    public Vector3 Position;
    public string Name;

}

I then want to have an exported list of these SnapPoints that I can add to and remove from in the inspector. I've seen controls like this on other nodes, for example, the CSG nodes, so I assumed it would be possible.
I've tried a few approaches. Some either didn't work or didn't work the way I'd like.
My first thought was to just export a list of these structs, but that doesn't work. Using C# collections or arrays results in a build error (The type of exported property is not supported) while using godot collections results in a Varient type error. I've also tried adding [System.Serializable] above the struct, though that didn't do anything. I also tried changing from a struct to a class, and that didn't help either.
So, I looked into using resources instead. I created a SnapPoint resource and have an export for that resource type. This works...but means I have to create a new resource for every snap point I have and is a bit of a pain.
I looked into writing a custom plugin with a custom inspector and that approach looked like it could get me what I was looking for, but seemed overly verbose for something as simple as this. Perhaps it isn't simple, but it sure seems like it should be in my mind. I'm fine doing this, I just wanted to see if anyone knew of a better approach before I went down that path.
So, ultimately, is there an easy way to get the functionality I'm looking for or is this a limitation of Godot's inspector? Or am I missing something fundamentally? I come from Unity and within their inspector this task is trivial.
I'm trying to capture images of MeshInstance3D via SubViewport and assigning them as textures to sprites as such:

@tool
extends Node2D

const PIXEL_PER_METER = 100.0
@export var btn := false : set=set_btn

func set_btn(new_val):
    if(new_val):
        assign_images()

func assign_images():
    var sub_viewport=$SubViewport
    var camera=$SubViewport/Camera3D
    var mesh_instances=[ $SubViewport/A, $SubViewport/B, $SubViewport/C ]
    var sprites=[ $A, $B, $C ]
    
    sub_viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
    camera.projection = Camera3D.PROJECTION_ORTHOGONAL
    
    for i in len(mesh_instances):
        var sprite=sprites[i]
        var mesh=mesh_instances[i]
        var mesh_aabb=mesh.get_aabb()
        camera.size = max(abs(mesh_aabb.size.x), abs(mesh_aabb.size.y))
        camera.global_position = Vector3(mesh.global_position.x, mesh.global_position.y, camera.global_position.z)
        sprite.position = Vector2(mesh.position.x * PIXEL_PER_METER, mesh.position.y * -PIXEL_PER_METER)
        #await get_tree().process_frame  # this doesn't work either
        sprite.texture=ImageTexture.create_from_image(sub_viewport.get_texture().get_image())

How ever this doesn't work, it doesn't capture the right image, nor does it place the sprite at right position relative to it's mesh counterpart:

For the image capture part, I suspect SubViewport & Camera3D isn't being updated quickly enough hence it captures the wrong image.
As for the position part, I believe 1 m in 3D translates to 100 pixels in 2D, maybe due to the unit differences the size & position of image is wrong.
So how do I implement this properly?
Note: I'm open to an alternate approach as long as it gives the same result, and no MeshInstance2D does not work
Minimal reproduction project (MRP)
I've set up a basic player.
It works when I place only one instance of it in a scene. I need two instances due to local multiplayer.
However, once I place two instances of it in a scene, it just moves out of my vision.
By observing where it's positioned using a basic print function, it starts moving in random directions crazily super fast for a few seconds, and then it's movement becomes normal.
Here's my code for it.
extends CharacterBody2D

@export var speed = 100
@export var dash_speed = 300
@export var prefix = ''
var dashing = false

@export var texture: Texture2D:
    set(v): 
        $Sprite2D.set_texture(v)

func _ready():
    $CPUParticles2D.emitting = false

func get_input():
    var input_direction = Input.get_vector(prefix + "left", prefix + "right", prefix + "up", prefix + "down")
    velocity = input_direction * speed
    if Input.is_action_pressed(prefix + "dash-jump"):
        velocity += input_direction * dash_speed
        dashing = true

func _physics_process(_delta):
    get_input()
    if dashing:
        $CPUParticles2D.process_material.gravity = Vector3(-velocity.x, -velocity.y, 0) / 2
        $CPUParticles2D.restart()
    move_and_slide()
    dashing = false

I don't know if the problem's in move_and_slide or something else. Don't mind the particles, and the input prefix is so the second player can use different input actions from the first one and be independent.
By the way, the texture variable exists so I can easily change it from Inspector, in case I wanna have a different sprite for player 2.
I would like to export my project as a web build, for which I am following the example given in these tutorials: tutorial1 tutorial2. This seems routine enough, but when I try to reproduce this, I get the following messages:

-Exporting to Web is currently not supported in Godot 4 when using C#/.NET. Use Godot 3 to target Web with C#/Mono instead.


-If this project does not use C#, use a non-C# editor build to export the project.

Screenshot of the errors
My project does not use C#. I am not sure what it means with a "non-C# editor build" and could not find anything about it.
Thank you for checking this out.
I am at a loss for what to do. I don't know what a "non-C# editor build" is.
I currently develop a game where the player moves a camera over a tilemap map to navigate. Unfortunatley as shown in the video below, the textures look weird when the camera is moving and I don’t know how to make them look sharp.
video: https://www.loom.com/share/f98c47207a0b4dcaaeae621ef1b028d9?sid=a6128b25-aa58-43ce-a140-26a17a07b743
Code of camera scene:
extends Camera2D

# Zoom variables
var min_zoom = Vector2(1, 1)
var max_zoom = Vector2(2, 2)
var desired_zoom = zoom
# Movement variables
var camera_speed = 500
# Map boundaries
var min_x_pos = 0
var max_x_pos = 2560
var min_y_pos = 0
var max_y_pos = 1360


func _physics_process(delta):
    if global_position != get_camera_position(delta):
        global_position = get_camera_position(delta)
#       var tween = create_tween()
#       tween.tween_property(self, "global_position", get_camera_position(delta), .2)


func _unhandled_input(event):
    if event.is_action_pressed("zoom_in"):
        desired_zoom = zoom + Vector2(.25, .25)
        if desired_zoom <= max_zoom and desired_zoom >= min_zoom:
            var tween = create_tween()
            tween.tween_property(self, "zoom", desired_zoom, .08)
    elif event.is_action_pressed("zoom_out"):
        desired_zoom = zoom - Vector2(.25, .25)
        if desired_zoom <= max_zoom and desired_zoom >= min_zoom:
            var tween = create_tween()
            tween.tween_property(self, "zoom", desired_zoom, .08)


func get_camera_position(delta):
    var new_camera_position = global_position
    if Input.is_action_pressed("ui_right") and new_camera_position.x <= 1984:
        new_camera_position.x += camera_speed * delta
    if Input.is_action_pressed("ui_left") and new_camera_position.x >= 400:
        new_camera_position.x -= camera_speed * delta
    if Input.is_action_pressed("ui_up") and new_camera_position.y >= 292:
        new_camera_position.y -= camera_speed * delta
    if Input.is_action_pressed("ui_down") and new_camera_position.y <= 1068:
        new_camera_position.y += camera_speed * delta
    return new_camera_position
I have a parent class (not node):
class_name Dragon

extends Area2D

@onready var dragon_frames = $DragonFrames

func _ready():
    rotation += deg_to_rad(60)

The inheriting class:
class_name FireDragon

extends Dragon

func _ready():
    dragon_frames.play("flying_red_dragon")

The FireDragon node is not rotating. The animation works fine. 
This works as expected:
class_name FireDragon

extends Dragon

func _ready():
    dragon_frames.play("flying_red_dragon")
    rotation += deg_to_rad(60)

Do some attributes not work with inheritance?
I'm using godot 4.2.1
I have a scene 'DragonSelector' which extends Area2D. The scene has a Sprite2D node called 'DragonSprite'.
DragonSelector.gd
class_name DragonSelector
extends Area2D

@onready var dragon_sprite = $DragonSprite

func _ready():
    pass 

func _process(delta):
    pass

func set_texture(dragon_texture: Texture):
    dragon_sprite.Texture = dragon_texture

I want to instantiate this scene in 'Main' scene and set the Texture on 'DragonSprite' in runtime.
Main.gd
class_name Main
extends Node2D

var dragon_selector_scene = preload("res://dragon_selector/dragon_selector.tscn")

func _ready():
    var dragon_selector_instance = dragon_selector_scene.instantiate()
    var texture = preload("res://dragon/flying_dragon-gold.png")
    dragon_selector_instance.set_texture(texture)
    add_child(dragon_selector_instance)
    dragon_selector_instance.position = Vector2(100, 100) 
    
func _process(delta):
    pass

This yields an error: Invalid set index 'Texture' (on base: 'Nil') with value of type 'CompressedTexture2D'. This is associated with the texture assignment line in set_texture:

To validate that the texture is where I think it is, I changed function set_texture to load the texture directly from within DragonSelector.gd:
func set_texture(dragon_texture: Texture):
    dragon_sprite.Texture = preload("res://dragon/flying_dragon-gold.png")
    #dragon_sprite.Texture = dragon_texture

This works as expected. Apologies for the vague title, I have no idea what to refer this to. Suggestions for correction are welcome.
Using godot 4.2.1
I have a game_board scene with only a root Node2D and no children.
I wish to programmatically create playing slots on this board.
These slots are to be instantiated from a separate scene file.
Since GDScript doesn't have a constructor, I wrote a static constructor initializing the required members (currently just a slot_id: int)
game_board.gd
extends Node2D

const play_slot_scene = preload("res://scenes/PlaySlot/play_slot.tscn")

func _ready():
    if not play_slot_scene.can_instantiate():
        push_error("Couldn't instantiate play slot")

    var firstSlot: PlaySlot = play_slot_scene.instantiate()
    firstSlot.slot_id = 0;
    
    add_child(firstSlot)
    
    for n in range(1,7):
        var nextChild = firstSlot.constructor(n)
        add_child(nextChild)

play_slot.gd
class_name PlaySlot
extends Node2D

const self_scene = preload("res://scenes/PlaySlot/play_slot.tscn")

@export var slot_id: int

static func constructor(id: int = 0)-> PlaySlot:
    var obj = self_scene.instantiate()
    
    obj.slot_id = id
    
    return obj

The code errors out at var firstSlot: PlaySlot = play_slot_scene.instantiate() because firstSlot is a Node2d obj (not an instance of PlaySlot class).
If I remove the static typing, the next line fails because slot_id does not exist on Node2D.
How do I instantiate these nodes with the right class?
TIA