0 votes

Hi,

I am new to Godot so I am sure I am making a simple, stupid mistake, any help is much appreciated.

I am trying to make a node that regularly spawns platforms off screen that will move until they are queue_freed when they make it to the other side of the screen. I am having difficulty when trying to call the .instance method.

I have tried a few different ways to call the floor node variable into the spawning script to no avail. Please help! :)


I am receiving the following error when trying to instance new platforms:

Invalid call. Nonexistant function 'insance' in base 'RigidBody2D'

Godot version: 3.2.1.stable.official

Local Tree:

  • FloorSpawn (Node2D)
    ---- Timer
    ---- Floor (RigidBody2D)

Script (attached to node root):

extends Node2D

onready var new_floor = $Floor

func _on_Timer_timeout():
    var new_floori = new_floor.instance()
    add_child(new_floori)

Floor.gd:

extends RigidBody2D

export var speed = -100


func _physics_process(delta):
    move_local_y(delta * speed)


func _on_DieArea_area_entered(area):
    queue_free()
asked Jul 17 in Engine by kingbard (12 points)

1 Answer

+2 votes

Your new_floor variable is a reference to an existing node "Floor". Nodes have no such method as instance().

instance() is a method of PackedScene - it takes a saved scene and creates all of its nodes/scripts/etc.

If you want to make a copy of an existing node, you can use duplicate(). Or you can save the floor object as a .tscn and then instance() it as many times as you need.

answered Jul 17 by kidscancode (17,766 points)

Aight that makes sense, thank you!!

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 How to use this Q&A? before posting your first questions.