#can't call method of instantiated scene
1 messages · Page 1 of 1 (latest)
There may be a mistake in how you did it.
What could be possible
There's no context here as to what you actually did. So i can't even guess.
Scene B is character, Scene A is protagonist
this is Scene A's script (truncated),
extends RigidBody3D
class_name Character
func pleasework():
print("oh. i did work.")
this is Scene B's script (also truncated)
extends Node3D
class_name Protagonist
...a bit later
func _ready() -> void:
$Character/EquipperArea.connect("area_entered",_on_area_entered)
$Character/EquipperArea.connect("area_exited",_on_area_exited)
$Character.apply_central_force(Vector3(0,0,3))
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
$Character.pleasework() #fails here
the error
E 0:00:00:368 Protagonist._process: Invalid call. Nonexistent function 'pleasework' in base 'RigidBody3D'.
<GDScript Source>protagonist.gd:55 @ Protagonist._process()
<Stack Trace> protagonist.gd:55 @ _process()
You instatiate it but use it in _ready already?
Where do you instatiate it?
Is it just an @onready ? and that doesn't fail, for this to work Scene B must be the root of Scene A, you sure $Character isn't returning null ?
Also make sure the right script is attached to the Scene A node
i instantiate in protagonist, i provided some pictures for help (protagonist is scene B, character is scene A)
But where do u do it? Is it added to the tree? Is it actually instantiating? Do u have the correct scripts attached to the nodes?
instantiate what? protagonist or character?
also im using the Instantiate Child Scene button to put character inside protagonist
The scene of character
Ahh i see now lol
print($Character)
print($Character.get_class())
print($Character.get_script())```
Do this in ready and see what it prints
If script prints null → script is not attached.
Make sure:
@onready var character: Character = $Character
func _process(delta):
character.pleasework()```
oh it does print null on script
one sec
yep that works
so you can't access methods on an instantiated scene even if the root of the actual scene has a script?
only print($Character.get_script()) is null
i can live with having manually to attach the same script to it but it certainly is strange that you can't access methods without that
do you have any other advice to say about this
or is that just how it is
I would have to test
Try to re add the node after saving ur scene character
But you for sure can access the script like this
ohh i get it now
so if i instantiate a scene, attach a script later to the actual scene, it does not transfer over
i guess that's it
thank you gentleman