New to scripting in C#, need to instance using a 2d array but don't know how, then I was wondering how to change the transform once instanced, since PackedScene loads as a node, not spatial, thus not allowing me to edit the transform in code.

This is the really basic code I have so far.

public class Map : Spatial
{
	private PackedScene _tile = GD.Load<PackedScene>("res://Tile.tscn");

	private int _numRow = 10;
	private int _numCol = 10;

	public override void _Ready()
	{
		Node tileInstance = _tile.Instance();
		AddChild(tileInstance);
		
	}

You'll probably want to store the tiles in a two dimensional list or similar and then use a for loop to initialize the tiles:

public class Map : Spatial
{
	private PackedScene _tile = GD.Load<PackedScene>("res://Tile.tscn");
	private int _numRow = 10;
	private int _numCol = 10;
	
	# the two dimensional list
	# you may need to import system.collections
	private List<List<Node>> tiles = new List<List<Node>>();
	
	public override void _Ready()
	{
		for (int x = 0; x < _numRow; x++)
		{
			List<Node> row = new List<Node>();
			for (int y = 0; y < _numCol; y++)
			{
				Node clone = _tile.Instance();
				AddChild(clone);
				row.Append(clone);
			}
			tiles.Append(row);
		}
		
		# then to access each element (for example)
		GD.Print(tiles[2][2].name);
	}
}

If you need to access the Spatial properties of the node, you will want to cast the node. The documentation shows a few different ways to do this, but I generally use the as keyword so I can check for null values:

Spatial example = tiles[2][2] as Spatial;
if (example != null):
	GD.Print(example.global_transform.origin)

Thanks for the reply, now I'm getting an error telling me that there is no function "append" for lists:

C:\Users\Bill Gates\Documents\map\Map.cs(25,10): 'List<List<Spatial>>' does not contain a definition for 'Append' and no accessible extension method 'Append' accepting a first argument of type 'List<List<Spatial>>' could be found (are you missing a using directive or an assembly reference?)

using Godot;
using System;
using System.Collections.Generic;

public class Map : Spatial
{
	private PackedScene _tile = GD.Load<PackedScene>("res://Tile.tscn");

	private int _numRow = 10;
	private int _numCol = 10;

	private List<List<Spatial>> tiles = new List<List<Spatial>>();

	public override void _Ready()
	{
		for (int x = 0; x < _numRow; x++)
		{
			List<Spatial> row = new List<Spatial>();
			for (int y = 0; y < _numCol; y++)
			{
				Spatial tile = (Spatial)_tile.Instance();
				AddChild(tile);
				row.Append(tile);
			}
			tiles.Append(row);
		}
	}

//  // Called every frame. 'delta' is the elapsed time since the previous frame.
//  public override void _Process(float delta)
//  {
//      
//  }
}

Sorry, the method is Add not Append. My bad :sweat_smile:

I feel bad crawling back here at the slightest hiccup, but I don't know what I'm doing. I'm trying to place the tiles in their respective position according to their x and y coordinates, and I thought the translate method in spatial would allow me to move them, but I get this error instead: C:\Users\Bill Gates\Documents\map\Map.cs(24,10): 'Spatial' does not contain a definition for 'translate' and no accessible extension method 'translate' accepting a first argument of type 'Spatial' could be found (are you missing a using directive or an assembly reference?)

{
	Spatial tile = (Spatial)_tile.Instance();
	AddChild(tile);
	row.Add(tile);
	tile.translate(new Vector3(x,0,y));
}

No problem!

In C# the API is slightly different in naming, using PascalCase instead of snake_case like in GDScript. So instead of translate what you will need to use is Translate instead and then it should work.

a year later