Can I instance a static body

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MemokingMH

onready var raycast = get_node(“RayCast”)

var held_item

if event.is_action_pressed(“interact”) and item_in_range:

held_item = raycast.get_collider()
var instance = held_item.instance()

This is my code. “Invalid call. Nonexistent function ‘instance’ in base 'StaticBody (” is the error it gives. “item_in_range” 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.

:bust_in_silhouette: Reply From: exuin

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.

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

MemokingMH | 2022-07-18 15:30

What is your code?

exuin | 2022-07-18 22:52

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

MemokingMH | 2022-07-19 10:59

Yeah but what is your new code with duplicate

exuin | 2022-07-20 03:34

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

MemokingMH | 2022-07-20 16:55