I have setup a MapCube.tscn scene. The scene has a Node3D and a child MeshInstance3D. Attached to the root node is a script:
# MapCube.gd
extends Node3D
class_name MapCube
## Create a new MapCube.
func initialize(pos: Vector3, is_walkable: bool = true, h: int = 0) -> void:
print("Mapcube instandiated", pos, is_walkable, h)
position = pos + Vector3.UP * h
scale = Vector3.ONE # Ensure default scale
I have another script that loads the above scene and instantiates a bunch of them to create a grid:
# Map.gd
extends Node3D
class_name MapGrid
## Width and height of the grid.
var width: int = 10
var height: int = 10
## 2D array of MapCube nodes.
var cubes: Array = []
## The packed scene to use for cubes.
@onready var Cube := preload("res://MapCube.tscn") as PackedScene
func _ready() -> void:
generate_grid()
## Generate the grid of cubes.
func generate_grid() -> void:
for z in height:
var row: Array = []
for x in width:
var cube := Cube.instantiate()
cube.initialize(Vector3(x, h, z), true, 0)
add_child(cube)
row.append(cube)
cubes.append(row)
When I run my scene the following happens:
I see a bunch of Mapcube instandiated in my output
I can see the “Remote” tab in my Scene filling with Node3D with MeshInstance3D
All of them have the correct position and correct scale.
None of them appear in my scene
Should I be able to see these instantiated objects in the scene view? If so, why can’t I see them?
Yes, you should see them. I don’t see anything wrong with your code.
Can you show a screenshot of how it looks like in your Remote tab and the 3D scene itself after instantiation?
No, the “3D” tab doesn’t show you the current state of the scene you’re running, only the original scene without any modification you’ve done to it at runtime, i.e. the instanced cubes.
You need to go to the “Game” tab - this is your currently running scene and you will see your cubes there. But you need to set up at least a simple camera and a directional lighting to see anything, otherwise it’ll just be pitch black.
You can do that in the Game window. See here I changed from “Input” to “2D” in the settings up top and then clicked AnimatedSprite2D in the game window - it highlighted the node and it shows me this node in the Remote scene view and the Inspector.