what does "Invalid call to function 'new' in base 'GDNativeClass'. Expected 0 arguments." mean?

d4v3y_5c0n3sd4v3y_5c0n3s Posts: 28Member

I am getting the following error:
Invalid call to function 'new' in base 'GDNativeClass'. Expected 0 arguments.

With the following code:
extends RayCast

const ray_length = 1000

func _input(ev):
if ev.type==InputEvent.MOUSE_BUTTON and ev.pressed and ev.button_index==1:
var camera = get_node("Camera")
var from = camera.project_ray_origin(ev.pos)
var to = from + camera.project_ray_normal(ev.pos) * ray_length

func _fixed_process(delta):
var space_state = get_world().get_direct_space_state()
# use global coordinates, not local to node
var col = get_collision_point()
var put = TestCube.new()
var idc = get_node(Position3D.new(set_name('ThisSpot')))
var result = space_state.intersect_ray( Vector3(0,0,0), Vector3(50,100,100) )

if (not result.empty()):
    load('res://Meshes/mvp_room_atmpt3.msh')
    idc.set_translation(col)

(it says the error is on line 16)

Answers

  • CalinouCalinou Posts: 143Admin Godot Developer
    edited June 2017 Answer ✓

    .new() (which lets you create a node using code) doesn't take any arguments, instead, you should call Position3D.new() without any arguments, and set the name afterwards using .set_name(). Remember that you also need to add_child() the resulting node, else it won't be added to the scene tree.

    Example for a Label node:

    func _ready():
        var label = Label.new()
        label.set_name("HelloLabel")
        label.set_text("Hello world!")
        add_child(label)
    

    You can inspect the scene tree of the running project at any time by opening the Debugger, then switching to the Remote Inspector tab.

  • d4v3y_5c0n3sd4v3y_5c0n3s Posts: 28Member

    Thanks Calinou! You are the best!

Sign In or Register to comment.