Godot Version
Godot 4.4
Question
Hello, I am trying to implement a strange inventory system. I have a drill that is a characterbody and couldn’t figure out how to translate that into a resource that I could use with the built in systems for inventory management, so I have a sprite2d box literally sitting in the map (at this game’s “base”) with an area2d that is checking for this drill item (which is in it’s own group). If the drill item is there and I press the “put in” button it deletes the scene, everything is good there.
However, when I try to “collect” the drill from this box, I am preloading the drill scene as a variable, and when the “collect” button is pressed, setting a new variable to be drill_scene.instantiate() and then setting the new variable’s property which relates to the character holding the drill, so it would be like the player character holding the drill instance as if they picked up the og off the ground.
But when that happens it errors out and tells me that the player character is a null_instance and I can’t access its properties. I didn’t think my logic for the character holding the item was awful, but maybe I am going at it all wrong. Here is what I think is the relevant code:
I have the player’s unique name in the drill script and in the inventory/storagebox script,
and then in the physics process of the drill script:
if drill_picked_up:
global_position = player.global_position
it works fine when I pick it up in the game world, but when instantiated acts like the player is a null_instance and won’t let me access the property,
here is what’s in the inventory/storagebox script:
if Input.is_action_pressed("COLLECT") and occupado and player_by_box:
occupado = false
drill_icon.visible = false
var drill = drill_scene.instantiate()
drill.drill_picked_up = true
get_tree().get_root().add_child(drill)
Thank you for reading.