Godot Version 4.2.2
I’m experimenting with trying to spawn and remove environment dynamically using this code.
func _ready():
var appartment1 = $Appartment1Area
worldspawn(appartment1)
func worldspawn(area_node: Area3D):
var appartment = preload("res://Appartment.tscn").instantiate()
appartment.global_transform.origin = area_node.global_transform.origin
add_child(appartment)
So far it works technically, seems to render as expected but I do get an error code when using “appartment.global_transform.origin = area_node.global_transform.origin”. Using it spawns the environment where I want it, not using it doesn’t. This is the error code I get with the line:
E 0:00:03:0050 Main.gd:30 @ worldspawn(): Condition “!is_inside_tree()” is true. Returning: Transform3D()
<C++ Source> scene/3d/node_3d.cpp:343 @ get_global_transform()
Main.gd:30 @ worldspawn()
Main.gd:9 @ _ready()
I’ve only recently been trying to learn how to code so I’m pretty amateur, if anyone has any insight on how to resolve or work around this error, I’d appreciate it. Even if it technically works I feel like I’m teaching myself to code like an idiot if I just let errors collect in my debugger.