Input bindings are deactivated after a while

Hi there, this is driving me crazy , I am binding my inputs in a class other than PlayerController (this class is just an abstraction of concept of gameplay) like this:



void SetUpGamePlayInputComponent(UInputComponent* InputComponent)
{
   NextOptionBinding=InputComponent>BindAction("NextOptionInput",EInputEvent::IE_Pressed,this,&UInteractiveGamePlay::OnNextOptionInput);
}


and I toggle input consummation like this:


NextOptionBinding.bConsumeInput = true; // or false

problem is, the binding stops working after a while, I logged it and I’m sure it stops calling bound function after a while (maybe 1 minute). To make sure the problem isn’t about bConsumeInput’s value, I commented it but it didn’t work. I have no idea what is going wrong, any idea?

Well the “code stops working after a minute or so” is a telltale sign of garbage collection destroying your object. Do you have any UPROPERTY pointers to it in another object? If you don’t, the GC sees that it’s not referenced by anything and destroys it. To confirm this, type “obj gc” in the command console while the game is running, if the input stops working then you have your culprit. You should add a UPROPERTY pointer to it in your game singleton or game instance class to keep it alive and have it available to other code, you could instead add your object to the root set to force it to not be GC’d, but then you might have trouble finding it again.