0 votes

onready var raycast = get_node("RayCast")

var held_item

if event.isactionpressed("interact") and iteminrange:

helditem = raycast.getcollider()
var instance = helditem.instance()

This is my code. "Invalid call. Nonexistent function 'instance' in base 'StaticBody (Pot.gd)." is the error it gives. "iteminrange" becomes true when raycast collides with an object(I tested this with print method it works fine). I want to destroy the object I'm looking at and create an instance of it in my hand. What is the problem with this code and is there a better way of doing this. I've been using godot for a fair bit of time but this is my first time looking into 3d so I don't get most diffrences and try to do things in same way I did in 2d so I'm sure this isn't the most efficient code.

Godot version latest
in Engine by (70 points)

1 Answer

+2 votes

It looks like held_item is not a PackedScene, which is what you call "instance()" on. You don't need to instance it as it is already an instance. Try using "duplicate()" instead.

by (8,152 points)

Thank you, I now can delete node I want. But it still doesn't add it as a child. Any idea on why that can be

What is your code?

I just started this project so other that what I posted there is just movement code

Yeah but what is your new code with duplicate

Thank you but I think I found a better way to handle this. Again thank you so much for help

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.