Godot Version 4.2.1
Question
I have my level scene level.tscn
and it’s script level.gd
. And I have platform scene platform.tscn
and it’s script platform.gd
.
platform.gd
extends Node3D
# Custom property
var length: float = 1.0
level.gd
extends Node3D
var platform_scn = preload("res://platform.tscn")
func ready() -> void:
var platform = platform.instantiate()
# I want to change length property of platform here
# I tried this
platform.length = 50.0
add_child(platform)
But this is not working.
You aren’t adding it to the scene, and you’re in a method that’s never called, what you need to do is:
func _ready() -> void:
var platform = platform.instantiate()
platform.length = 50.0
add_child(platform)
Oh I forgot to mention I did added it to scene using add_child()
. It is showing in the level but length property never get called:
var length: float = 1.0:
set(value):
length = value
print("Value change!")
This doesn’t ge print when I set the length property
Please do make sure your code is the real code or no one can help you with it
The code doesn’t have that setter
This is not the real code this is just a presentation of it to understand the question. My question is I instantiating a scene which has length property I wan to change it with my main scene.
It should work, but impossible to tell what might be wrong with your example 
I have my level scene level.tscn
which has MeshInstance3D as root and it’s script level.gd
. And I have platform scene platform.tscn
and it’s script platform.gd
.
level.gd
extends Node3D
var platform_scn = preload("res://platform.tscn")
func _ready() -> void:
var platform = platform_scn.instantiate()
platform.transform.origin = Vector3.LEFT
platform.length = 100.0
add_child(platform)
platform.gd
extends MeshInstance3D
@export var length: float = 1.0:
set(value):
length = value
mesh.size.x = value
func _ready() -> void:
mesh = BoxMesh.new()
mesh.size = Vector3(length, 20, 8)
This is the real code. Origin of platform changed but size.x not changed when I set length.
Does it work if you do:
mesh.size = Vector3(value, mesh.size.y, mesh.size.z)
It does even in level.gd
when I do it.
platform.mesh.size = Vector3(100.0, platform.mesh.size.y, platform.mesh.size.z)
or this
platform.mesh.size.x = 100
but I can’t modify custom defined length property