My TileMapLayer doesn't want to appear when modified by code

Godot Version

4.5

Question

Hello everyone

I created a subclass of a TileMapLayer called ArrowPath, present just there :

If it’s not supposed to show right now, the point is, for now, to show the tiles in range of a unit when we click on it

For instance :

Here is the code for ArrowPath (in C#) for now

public partial class ArrowPath : TileMapLayer
{

	/// <summary>
    /// Set multiple cells inside the TML
    /// </summary>
    /// <param name="cells">The amount of cells</param>
	public void SetCells(List<Vector2I> cells)
	{
		GD.Print("SetCells called");
		foreach (Vector2I item in cells)
		{
			SetCell(item, 0, new(2,2));
		}
		GD.Print("SetCells says :",GetUsedCells());
	}

}

And here’s the TileSet I use

”Is it because you don’t call SetCells ?”

No. Here’s what happens after I click on one of those beautiful stickmen

image

And yet :

Before

After

I am newish on Godot so maybe there’s something I miss ? Thank you in advance

OK, I got the solution. It wasn’t in the context, but with the help of this forum post, I was able to understand what I was doing wrong :

First : to understand the solution, I changed the disposition to this

Alright. You see “Main” ? It uses a script called Map.cs. Here’s what was causing an issue :

public partial class Map : TileMapLayer{
  ...
  public ArrowPath ArrowSet = new();
  ...
}

Don’t see it ?

It’s precisely the “new();” that was messing everything. Because if it creates a C# instance, it doesn’t create a node, nor call the one already present

How to fix it ? Simple.

public partial class Map : TileMapLayer
{
    
    public ArrowPath ArrowSet;

    
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        // OnReady :

        ArrowSet = GetNode<ArrowPath>("ArrowPath");
        
    }
}

This way, I am sure that I get the node

Still, thank you for your help