Skip to content

[Depreciated] World Interaction (Override Input On a per Object Basis)

Mitchell McCaffrey edited this page Dec 10, 2016 · 1 revision

##Override Input On a per Object Basis

The default interaction mechanic is to pickup an object with the grip button and drop the same object when the button is released, however for some objects that isn't what we need. Maybe it's a gun or torch that the player will need to hold for a while, in that case it would be nice if we can override this default input on a per object basis.

The problem with this lies in the fact that when we add a input node into a blueprint there is no way to tell that node to consume or not consume input (overriding the pawns input) at run time. This leads to the problem that if we pickup an object that wants to override the pawns drop behaviour it will override the drop for both the left and right hand despite only being held in one of them.

The solution to this is a little odd and a tiny bit inefficient but what we will do is create two "Actor" blueprints one that on spawn will override the left hand input and the other that will override the right hand input. To override the input at run time we will simply spawn these actors when we need and destroy them when we want to reset our input.

Note: this is a follow up to the Basic Pickupable Blueprint and Handling Collision on Pickup tutorial

###Overriding Input at Run Time

Here is what a base class for this type of input consumer blueprint would look like

  1. The consumer has two Event Dispatchers that allows outside blueprints to hook into the event we want to override
  2. When the consumer is spawned we need to enable input
  3. When the consumer is destroyed we want to unbind all the events from our dispatchers then disable the actors input

To actually use this blueprint we will create a child blueprint of our input consumer and call the events on the event we want to override

Next actually in our object we will override the input on pickup.

  1. First we get the hand of our current interactor
  2. Switching on the left or right hand we spawn the left or right hand input consumer giving it some dummy transform
  3. Lastly we bind to our new spawned consumers pressed event and tell our interactor to drop the picked up object when we press our button again

The very last thing we need to make sure to do is destroy the input consumer when the drop event is called

And that's it.

Now we can override any input we need at run time

-Mitch