0 votes

help! godot kep calling this error, this is the code:

onready var Alien = get_tree().get_root().get_node("Level 1/Alien")
onready var muzzle = get_tree().get_root().get_node("Level 1/Player/Muzzle")

func _ready():
    if Global.araragi:
        #var copy = preload ("res://Actors/Alien.tscn") 
        var copy = Alien.duplicate()
        owner.add_child(copy)
        copy.transform = $Muzzle.global_transform

the error is in the line "owner.add_child(copy)" I used duplicate and preload but none works, I even use the print to know that "copy" exist and tells me its name is KinematicBody2D:1261, but still doesnt work.

I used a similar code in other scene and worked fine.

Godot version Godot_v3.2.3-stable_win64
in Engine by (12 points)

Try to run print(owner), it looks like owner is null

you are right! owner is the one null, but I don't understand why it worked in another scene but not here

1 Answer

+2 votes

at first, please download the current version of Godot (3.5) an use that instead. 3.2 is pretty old.

The problem is not copy, but owner.
I can only guess, but probably you want get_tree().current_scene instead.

by (1,534 points)

you are rgiht, owner is null haha, thank you, what I don't understand is why it worked in another scene though

so I use the gettree().currentscene instead of owner? and sorry for asking too much, I'm a noob in game programming

I'll download the latest godot version too

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.