- Edited
Hi, I am just starting a new project which I would like to be mod friendly.
I will need to have different kind of buildings, so I thought to have a basic scene and then to modify it as necessary.
The basic scene is like this:
Node3D
- MeshInstance3D
- StaticBody3D
- CollisionShape3D
The mesh and the collisions shape are set as a 1x1x1 cube
Attached to this scene I have the following script
extends Node3D
class_name Building
var building_data: Dictionary = {}
func _ready():
if building_data.is_empty():
load_default_data()
update_visuals()
func load_default_data():
var json = FileAccess.open("res://data/buildings/house.json", FileAccess.READ)
if json:
building_data = JSON.parse_string(json.get_as_text())
func update_visuals():
# Load mesh
var mesh_path = building_data.get("mesh")
if mesh_path != "":
var mesh_resource = load(mesh_path)
if mesh_resource:
# Replace the mesh
$MeshInstance3D.mesh = mesh_resource
# Update collision shape
var size : Array = building_data.get("footprint_size")
var shape = BoxShape3D.new()
shape.size = Vector3(size[0], size[1], size[2])
$StaticBody3D/CollisionShape3D.shape = shape
Data are loaded from this json file
{
"id": "house",
"mesh": "res://models/house.glb",
"footprint_size": [5, 1, 3]
}
The current situation is that launching the game with update_visuals()
disabled, I see the 1x1x1 cube on the ground, if I enable the update_visuals()
function I see nothing on the ground. That should means that something happens, but not what I want.
The .glb file was created using Blender removing the light and the camera and changing the cube's size to (5, 3, 1), then into Godot, double clicked on it and imported it including Mesh + NavMesh.
What am I doing wrong?
mesh_path
is set correctly, adding a print(mesh_path)
, the correct path is shown into the console.
Is there a better approach to be mods oriented about the buildings? I am at the very beginning of the project, I'm ust deciding how to design it, so I can easily start over.