0 votes

im an a beginner dev still experiment on stuff. im trying to create a spawner using the position2d but some code result as "First argument of yield() is null.". is there a way to fix this.
here is the pos2d code

extends Position2D

signal spawned(spawn)

export(PackedScene) var spawnling_scene
export var spawnrad = 100

func _on_EnemyTimer_timeout():
  var spawnling = spawnling_scene.instance()
  
  
  
  
  add_child(spawnling)
  spawnling.global_position = global_position
  return spawnling

and here is the enemy script

>    extends KinematicBody2D class_name Enemy
> 
> export var speed = 100
> 
> onready var enemy = get_node_or_null("/root/world/enemy") onready var
> player = get_node_or_null("/root/world/player") var velocity =
> Vector2.ZERO var path: Array = [] # contain destinations positions var
> nav = null var thereshold = 16
> 
> func _ready():
>   yield(owner, "ready")
>   nav = owner.nav
>func _physics_process(_delta)
>   if path.size() > 0:
>       move_to_target()
>   look_at(player.global_position)
>func move_to_target():
>   if
>              global_position.distance_to(path[0]) < thereshold:
>               path.remove(0)
>   else:
>       var direction = global_position.direction_to(path[0])
>       velocity = direction * speed
>       velocity = move_and_slide(velocity)
>func get_target_path(target_pos):
>   path = nav.get_simple_path(global_position, target_pos, false)
in Engine by (19 points)
edited by

1 Answer

+1 vote
Best answer

It means that your enemy doesn't have an "owner". Do you want to yield to the parent nodes ready? In which case use get_parent() instead of owner

by (1,340 points)
selected by
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.