#How to apply variables to an instanced scene using the function that instanced it?

9 messages · Page 1 of 1 (latest)

gritty drum
#

I am new to godot.
I am trying to make a script that instanced the same scene repeatedly but each instanced scene will have their individual variables set through the instance function so they all behave differently.

func blockinst(pos, type):
var instance = block.instantiate()
instance.position = pos
instance.tile = preload("res://Content/Tiles/Dirt/Dirt.tres") <- this is what is not working.
add_child(instance)

despite the instance.pos = pos correctly setting the position of the instance the instance.tile gives me this error:

Invalid assignment of property or key 'tile' with value of type 'Resource (Block)' on a base object of type 'Node3D'.

also blockinst(Vector3(0, 0, 0), wood) this is what triggers the function, it contains the location and what set of variables will be applied to the instance it is making, here it would be wood.

How can i get the variable to be assigned validly to the instance it is creating?

rich hazel
gritty drum
#

Now I am getting this error:

#

Invalid call. Nonexistent function 'instantiate' in base 'Resource (Block)'.

terse belfry
#

resources other than scenes are more intended as data containers for other objects to use, like a texture or a collision shape.

#

so it looks like what you're trying to instanciate isn't actually a scene.

gritty drum
#

ok, but how can i make an instanced scene read all the variables in a .tres fil?

terse belfry