Instantiated cubes are in my scene but invisible

Godot Version

4.4.1_stable

Question

I’m not exactly sure how to explain this but:

  1. 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
  1. 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:

  1. I see a bunch of Mapcube instandiated in my output
  2. I can see the “Remote” tab in my Scene filling with Node3D with MeshInstance3D
  3. All of them have the correct position and correct scale.
  4. 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?

Just nothing. It’s not a scale or a position issue either, if I press “F” on one of the Objects it just brings me back to 0,0,0.

And your game view? It’s also just empty?
Do you have a camera, lighting etc. set up?

I don’t have anything else in my scene. Does that matter? I’m just moving over logic from C# step by step so I haven’t set up camera or light.

I should still be able to the cubes in my scene though, right?

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.

I can only see “Game embedding is not available on your OS”.

Sorry I’m very confused haha

I never used Godot on Mac, so can’t tell you for sure, but maybe turning this off will help?

Your game should run in a separate window with a DEBUG in the name

Just to clarify: It’s not possible to view the scene as its updated during the game and can only view my game through the actual game window?

There’s no way to visually inspect objects in a Scene-like view during gameplay?

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.

I have to admit it’s not as intuitive as in Unity, which you’re probably coming from, but it works alright. Just takes getting used to.

1 Like

Ah man that’s very very unfortunate. In the debug window I can’t click my meshes at all so it’s quite difficult to understand what’s going on.

Thank you for the help either way

Why not? just need to make sure this 3D is clicked, and as you can see I can click on the MeshInstance3D to select it right in the game view.

1 Like

Aha, you’re right that’s what I was missing! Thank you

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.