Player not colliding with gridmap

Godot Version

4.3

Question

Hello,

I have 3 scenes and the correlating scripts: World(gridmanager), player(player), and node3d (N/A). My player falls through the gridmap. Collision is not colliding/

Wold tree:
World(Node3d)>gridmap,player

Player:
Player(CB3d)>CollisionShape,MeshInstance,camea,head

Node_3d
node_3d>MeshInstance3d(box, (1,1,1))> staticbody3d> collisionshape 3d.
The nodes are nested in that order.

The scripts execude, the 10x10 grid is drawn, but the player falls through the floor. In addition to the code, I’ve also enable collision layer and mask and priority to 1 in the editor.

I don’t know, I’ve ripped down the node_3d 1x1x1 box and rebuilt it, and rebuilt my player, and pulled everything else out of the world except the WorldEnvironment. Player spawns above the gridmap and falls through. Zero collision.

player.gd
extends CharacterBody3D

@export var structures: Array[Structure] = []
@export var selector: Node3D # The 'cursor'
@export var selector_container: Node3D # Node that holds a preview of the structure
@export var view_camera: Camera3D # Used for raycasting mouse

@export var camera: Camera3D
@onready var head: Node3D = $Head

<SNIP>

var index: int = 0 # Index of structure being built

func _ready():
<SNIP>
	# Spawn the player above the grid
	velocity = Vector3.ZERO
	global_transform.origin = global_transform.origin + Vector3(2, 5, 2)
	collision_layer = 1
	collision_mask = 1
	collision_priority = 1 

<SNIP>


gridmanager.gd

extends Node

@export var gridmap: GridMap
@export var terrain_block_scene: PackedScene
var mesh_library: MeshLibrary

func _ready():
# Initialize MeshLibrary
mesh_library = MeshLibrary.new()

# Load terrain block mesh
var terrain_block_mesh = get_mesh_from_scene(terrain_block_scene)
if terrain_block_mesh:
	# Add terrain block to MeshLibrary
	var block_index = mesh_library.get_last_unused_item_id()
	mesh_library.create_item(block_index)
	mesh_library.set_item_mesh(block_index, terrain_block_mesh)
	
	# Assign MeshLibrary to GridMap
	gridmap.mesh_library = mesh_library

	# Configure collision layer and mask
	gridmap.collision_layer = 1
	gridmap.collision_mask = 1

	# Generate the grid
	generate_grid(gridmap, block_index, Vector2i(10, 10))
else:
	print("Error: Mesh not found in terrain block scene.")

func generate_grid(gridmap: GridMap, block_index: int, size: Vector2i):
# Generate a grid with the terrain block
for x in range(size.x):
for z in range(size.y):
gridmap.set_cell_item(Vector3i(x, 0, z), block_index)

func get_mesh_from_scene(scene: PackedScene) → Mesh:
# Extract mesh from the scene
var instance = scene.instantiate()
if instance and instance is Node:
for child in instance.get_children():
if child is MeshInstance3D:
return child.mesh
return null


data_map.gd

extends Resource
class_name DataMap

@export var cash:int = 10000
@export var structures:Array[DataStructure]

func generate_grid(gridmap: GridMap, mesh_library: MeshLibrary, block_index: int, size: Vector2i):
print(“(data_map.gd)MeshLibrary item count:”, mesh_library.get_reference_count())

# Loop through a 10x10 grid and set each cell to use the terrain block
gridmap.set_collision_layer_value(1,true)
gridmap.set_collision_mask_value(1,true)
for x in range(size.x):
	for z in range(size.y):
		gridmap.set_cell_item(Vector3i(x, 0, z), block_index)

how is your mesh-library set up?