Input and InputEvent detection - not working as expected ?

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

Hi all,

I think i am missing something while working with input() and _inputevent() callbacks.
I want to pickup a RigidBody using touch / mouse left button pressed but only release it when the touch is “unpressed” (even if this event happens NOT on the rigidBody).

I have one script attached to my RigidBody, noting that main scene contains many instance of this rigidbody. (I removed the debugging prints below).

Initialisation:
var mCurLiftedBody = null

PickUp: (In order to catch the “pressed” event on this rigidbody)

func _input_event(camera, event, pos, normal, shape):
if (event is InputEventMouseButton and event.is_pressed() == true):
        	self.get_node("Mesh").set_surface_material(0, null)
        	self.set_mode(  MODE_STATIC ) 
        	#mCurLiftedBody = self
        	mCurLiftedBody = get_node(".")
          pass

Release (Anywhere on the screen)

func _input(ev):
	#if(ev is InputEventScreenTouch && ev.pressed == false):
	if(ev is InputEventMouseButton && ev.pressed == false):
	
	if( mCurLiftedBody != null):
		mCurLiftedBody.set_mode( MODE_RIGID )
		mCurLiftedBody.get_node("Mesh").set_surface_material(0, null)
		mCurLiftedBody = null

My problem is, not that it is not working, but that it is not Always working…

Sometimes the prints are working correctly (picked up / released) sometimes not.
Sometimes the prints are working correctly but the mesh isn’t being nullified …

I checked this and this too but couldn’t find the answer.

The main scene contains other rigid and static bodies and collision occurs but I don’t think the problem is from there…

:bust_in_silhouette: Reply From: GameVisitor

Solved it myself, can sleep parameter was the issue…