I have a State Machine-driven approach to handling actions in the game world. I have a specific state thrown when a player KinematicBody conducts a transition near an object in the game world. Inside this state, I need to get all the colliding objects, so I can pull out the applicable item type and add that to the player's inventory.
#player's physics process
if(Input.is_action_pressed("INTERACT")): # E button pressed
$FSM3D/States/Interact.enter("Idle", "InteractWithObject", get_node(".")) # top level node is parent KinematicBody
# Inside the Interact
func enter(fromStateID=null, fromTransitionID=null, inArg0=null,inArg1=null, inArg2=null):
#inArg0 is the active Player node from the calling class, which is KinematicBody
var player = inArg0
var collisions = player.get_colliding_bodies() #Not working, not sure what method to use
var element = player.get_collider()
# HPRecovery1 is the name of the element in the game world, a Mesh/RigidBody
if element == "HPRecovery1":
print("Colliding with HPRecovery")
# Move to Inventory
I am not clear on what method to use to get all colliding meshes, if such a method exists for deferred instances of an object. What would be the best approach to get collided objects inside the State?