I am completely stumped as to why in this code:

MazeGenerator maze = new MazeGenerator();
var mazeTilemap = GetNode<Godot.TileMap>("/root/Game/Maze/MazeTilemap");

Vector2 posToMove = (Vector2)mazeTilemap.Call("IsTileFree",Position,direction);
Vector2 posToMove1 = maze.IsTileFree(Position,direction);

posToMove1 returns a different Vector to posToMove!

For context, MazeGenerator is the name of the script attached to my MazeTilemap node which has cell size of 32,32 and has collision on "wall" tiles. When I use mazeTilemap.Call("IsTileFree"), it returns the correct position and my character collides with the walls on the tilemap. However, when I use maze.IsTileFree(), the Vector returned is double posToMove and collision doesn't work!

I suspect when I use maze.IsTileFree() it is using a default 64,64 tilemap with no collision instead of my MazeTilemap but I don't understand why?? It doesn't make sense as to why it would do that..

Does anyone know what is going on here? What is actually happening when I create an instance of MazeGenerator and why is using that instead of a reference to the node giving me different values?

  • Kojack I figured it out, MazeGenerator was inheriting Tilemap which meant it was getting values from a default tilemap node, whereas GetNode(MazeTilemap) was actually getting the values from my tilemap node

The line:

MazeGenerator maze = new MazeGenerator();

is making a new instance of a MazeGenerator. So you have two different MazeGenerators, one temporary one made in that code referenced by the variable maze, and a different MazeGenerator found on the node and referenced by the variable mazeTilemap.

    Kojack I understand that but I don't get why when I call the same method from both of them they return different things? Is the instance of MazeGenerator (maze) not sharing the same properties my MazeGenerator script?

    I don't know what's in MazeGenerator, so I don't know what it does when you make one.
    I would assume it has randomness, so making two of them would mean two different random mazes, giving different results for the same call.

      Kojack I figured it out, MazeGenerator was inheriting Tilemap which meant it was getting values from a default tilemap node, whereas GetNode(MazeTilemap) was actually getting the values from my tilemap node