xyz Sorry, but I don't understand, where is a node attached?
Could it be in the function parameters? I've already changed the parameters of all the functions from Node to Node2D and it's still giving me the same error, the value being passed by the 'root' parameter is of type Node2D and the root of the file that is read is also a Node2D
Here are the changes I had already made before:
using System.Collections.Generic;
using System.Linq;
using Godot;
using LittleDragonAlpha.scripts.map.grid;
namespace LittleDragonAlpha.scripts.map;
public static class ChunkLoader
{
private const string RoomsPath = "res://assets/resources/rooms/";
public static List<Room> InstantiateGrid(Node2D root, Grid grid)
{
return (from Chunk chunk in grid.Chunks
select InstantiateRoom(root, chunk)
into room
where room != null
select room).ToList();
}
private static Room InstantiateRoom(Node2D root, Chunk chunk)
{
const int roomName = 0;
if (chunk.Name == "0") return null;
var file = chunk.SpecialChunk
? $"{RoomsPath}{chunk.Name}/{chunk.Binary}/{roomName}.tscn"
: $"{RoomsPath}{chunk.Name}_{chunk.Binary}/{roomName}.tscn";
if (FileAccess.FileExists(file))
{
var scene = GD.Load<PackedScene>(file).Instantiate();
GD.Print(scene.GetType() + " " + root.GetType());
root.AddChild(scene);
return null;
}
GD.PushWarning($"File {file} not Find!");
return null;
}
}
The logs were the same, here they are again, for sanity check(this time running using Node2D as parameter):
WARNING: File res://assets/resources/rooms/A/0010/0.tscn not Find!
at: LittleDragonAlpha.scripts.map.Room LittleDragonAlpha.scripts.map.ChunkLoader.InstantiateRoom(Godot.Node2D, LittleDragonAlpha.scripts.map.grid.Chunk) (res://scripts/map/ChunkLoader.cs:37)
ERROR: Script inherits from native type 'Node2D', so it can't be assigned to an object of type: 'Node'.
at: instance_create (modules/mono/csharp_script.cpp:2420)
Godot.Node2D Godot.Node2D
ERROR: Script inherits from native type 'Node2D', so it can't be assigned to an object of type: 'Node'.
at: instance_create (modules/mono/csharp_script.cpp:2420)
Godot.Node2D Godot.Node2D
ERROR: Script inherits from native type 'Node2D', so it can't be assigned to an object of type: 'Node'.
at: instance_create (modules/mono/csharp_script.cpp:2420)
Godot.Node2D Godot.Node2D
ERROR: Script inherits from native type 'Node2D', so it can't be assigned to an object of type: 'Node'.
at: instance_create (modules/mono/csharp_script.cpp:2420)
Godot.Node2D Godot.Node2D
ERROR: Script inherits from native type 'Node2D', so it can't be assigned to an object of type: 'Node'.
at: instance_create (modules/mono/csharp_script.cpp:2420)
Godot.Node2D Godot.Node2D
ERROR: Script inherits from native type 'Node2D', so it can't be assigned to an object of type: 'Node'.
at: instance_create (modules/mono/csharp_script.cpp:2420)
Godot.Node2D Godot.Node2D
WARNING: File res://assets/resources/rooms/B/0101/0.tscn not Find!
at: LittleDragonAlpha.scripts.map.Room LittleDragonAlpha.scripts.map.ChunkLoader.InstantiateRoom(Godot.Node2D, LittleDragonAlpha.scripts.map.grid.Chunk) (res://scripts/map/ChunkLoader.cs:37)
WARNING: File res://assets/resources/rooms/D/0100/0.tscn not Find!
at: LittleDragonAlpha.scripts.map.Room LittleDragonAlpha.scripts.map.ChunkLoader.InstantiateRoom(Godot.Node2D, LittleDragonAlpha.scripts.map.grid.Chunk) (res://scripts/map/ChunkLoader.cs:37)
WARNING: File res://assets/resources/rooms/C/0100/0.tscn not Find!
at: LittleDragonAlpha.scripts.map.Room LittleDragonAlpha.scripts.map.ChunkLoader.InstantiateRoom(Godot.Node2D, LittleDragonAlpha.scripts.map.grid.Chunk) (res://scripts/map/ChunkLoader.cs:37)
note that I wrote a line GD.Print(scene.GetType() + " " + root.GetType());
just to demonstrate what root and scene are, and the logs are always Godot.Node2D Godot.Node2D
, demonstrating that both are Node2D