Posses a Pawn blueprint in VR

Hello!

I’ve been trying to make a motorcycle in VR (basic template), where I have coded the logic for how it should drive in a Pawn Blueprint. For this I have made two input actions (throttle and steer) that I have made an input mapping context for those that I call (“Add mapping context”) at “begin play” in the motorcycle blueprint (where I also use “get player controller” with index set to 0).

I then try to click the button that I assigned to “IA_throttle” (the x button on oculus controller) and nothing happens. I added a print string to see if it fires but it doesn’t, although a print string that I added to “begin play” in the motorcycle blueprints fires every time. I have tried to change around the input type for the actions, I have even tried to add it to the “IMC_Default” just to see if it works, but nothing is working so far.

My question is: can you not remotely activate a pawn blueprint if you are not possessing it? And if so, what is the best way to possess a pawn blueprint while in VR (without interfering with the VR aspect etc.)?

Inputs go thru PlayerController. You could put your input action event in your PlayerController, and pass the action to a reference of your pawn. Add custom event or function on your pawn “HandleThrottle” and call that w your PlayerController.

If you want to possess in VR it’s the same as flatscreen. On your motorcycle pawn, you need your vrorigin setup and may need motion controllers and hands depending on how you expect to interact with the environment. Start w copying over from vrpawn setup to get started.

First of all, thank you so much for your response!

So I took a look at PlayerController and that seems to be purely a c++ function, which I don’t know what to do with unfortunately. I was wondering if you know how I could pass the input action from my input mapping context to this kind of setup:

I have set up the logic for the input actions in the same blueprint (motorcycle pawn), and the throttle one is mapped to “x” on oculus controller for example.

Image: When I grab the steering wheel with OnGrabbed, I want to be able to call on the throttle input action somehow to be able to use that event continuously until I let go of the steering wheel. I looked and I can’t call an actual input action via the “set timer by event” node unfortunately, it doesn’t have the red square on top.

Do you know how I could make this happen? I really appreciate the help!

I didn’t put any c++ stuff in my response above… if youre talking about HandleThrottle, I meant that is a function you create in your MotorcyclePawnBP to take input and apply it to whatever system you’re using to move the pawn around (systems like Chaos Vehicle, MovementComponent, custom velocity stuff)

This is how I would implement a handlebar(names may be a bit different i dont vr sample open):

Create an IMC_ThrottleHandle, this has IA_HandBrake on oclulus control R hand trigger as a axis 1D input, IA_Throttle mapped to X

In your RightHandleBarBP’s
VRGrabcomponent->OnGrabbed:
PlayerController(0)->EnhancedInput..->AddMappingContext(IMC_ThrottleHandle)

OnReleased (or whatever the event for releasing is):
PlayerController(0)->EnhancedInput..->RemoveMappingContext(IMC_ThrottleHandle)

Then, in your MotorcyclePawnBP, you create events to handle the inputs. These events only get called when the MappingContext is added, so wont fire when the handle isnt grabbed.

EnhancedInput.. IA_Throttle → Started (fires when action starts) → “HandleThrottle” (your custom fcn)
EnhancedInput.. IA_Throttle → Canceled and Completed → “ZeroThrottle” (another custom fcn to set your throttle to 0)

You might pipe in the ActionValue into an input on HandleThrottle for you to use in your motion system, if you need it. Buttons(digital bool) will return 0 or 1, triggers(axis 1D) return a range 0 to 1 depending on how much the trigger is pulled.

For a handbrake:
EnhancedInput.. IA_Handbrake → Triggered (fires continuously) → “HandleHandBrake” (your custom fcn)
Same as above for canceled/completed.

For a trigger or thumbstick axis, use Triggered as Started only gets called when you first start the input, Triggered is called on tick and allows the ActionValue to get piped in constantly.

You can create an IMC_ClutchHandle for left hand. Or IMC_Right_Mirror if you wanted to create a right hand mirror to adjust for instance. Follow the same pattern.

You can look at the VRPawn’s beginplay to see this in action for assigning the input context. and how the inputs are handled there.

To possess a pawn you do PlayerController->Possess(self) like in your MotorcyclePawnBP, or you can possess within your custom Playercontroller BP with a reference to the pawn calling Possess(mymotorcycleBPref). Either way works fine, I prefer the second as it keeps possession logic in my playercontroller.

Tons of info/vids out there of possessing vehicles/etc essentially doing the above… its the same for VR, you just have to set up the pawn you want to possess as a ‘VRPawn’ essentially.

For possession of different vehicle pawns, Instead of BeginPlay use ReceiveControllerChanged event in your pawnBP to clear and add initial MappingContexts. This fires when the pawn is possess/unpossessed. Beginplay will only fire once when the pawn is initialized.

1 Like

Thank you so much for your response, this is an incredible answer! I think I am just around the corner from making this work, but the input mapping context is still not working

I did as you suggested and added the input mapping context when I grab the steering wheel, and drop it when I release. As you can see I have a print string after on grabbed.

When I grab the steering wheel the print string prints in the console, so I know that the OnGrabbed works, but when I try to press the X button on the oculus controller nothing happens. For some reason the input mapping context isn’t added, despite me using the motion controller reference (that I pass through the OnGrabbed default blueprint) to add it. Any idea why it’s not being added?

Add and remove mapping context to PlayerController not motion controller, all input goes thru PlayerController-EnhanchedInput… See VR pawn beginplay for example. Motion controller passes VR controller motion and location data nothing to do with buttons.

Research the PlayerController and it’s use in unreal. You will need to be familiar with it to do things proficiently.

Hello again, I’m sorry for pestering you with so many questions but I am incredibly frustrated that this doesn’t work lol. I have read up on player controllers, I’ve watched specific VR tutorials on how to implement input actions and mapping contexts, and though I copy it exactly it still doesn’t work!

When I grab the steering wheel, the print string “steering grabbed” shows up, when I drop the steering wheel the string “DROPPED STEERING” shows up, yet as I’m holding it nothing happens at all when I press “X” on my oculus controller.

I’ve tried to include a picture of every single element involved below (I will post in four comments, since I can only post 1 image per comment). Can you see anything that is wrong that might explain why the input action doesn’t fire? I greatly appreciate all of your help!

(I’ve tried connecting every pin on IA_Throttle to the print string after, triggered etc.)

pic 1:

pic 2:

pic 3:

pic 4:

I think the problem is your IMC_Motorcycle is conflicting with some other IMC. This can be ‘fixed’ by giving your IMC_Motorcycle a higher priority when you add it, but the actual fix is controlling your IMC stack, esp if you expect to be able to switch behaviors based on what you grab/interact with.

You don’t want to add all the IMCs to default mapping contexts in the project settings. those get applied to the playercontroller inputcomponent immediately. control your mappings yourself so you can switch them out as needed. I would clear out that array in the project settings, it’s not needed… it’s there for convenience.

On beginplay in your playercontrollerBP add your default mappings you will always need. I put this in a function, like “InitDefaultControlMappings”, so i can call it later if i want to just clear all my mappings and start from scratch. It’s sometimes easier than trying to figure out what to remove.

Set the priority of your IMC_Motorcycle to 9 when you add it (or 1 or 50, it’s up to you, how you want to give them ‘priority’ over each other in the stack, higher number wins the priority).

In your InputActions there is a setting “Consume Lower Priority Enhanced Input Actions” that you can uncheck to let the IA percolate down the priority chain… it’s probably not something you want to do in this case, but it’s good to know it exists.

Also, make sure you’re possessing the MotorcycleBP pawn with your playercontroller. Otherwise the IA’s wont fire on MotorcycleBP, it will try to fire on your current pawn.

This did the trick! When I use the “possess” node with player controller I can now use the input actions!

Now I have a world of other issues, such as the VR camera not going away and my possess camera hovering above it, but the main issue of not being able to access input actions is solved! Thank you so much friend, I very very much appreciate all your help! :smiley:

1 Like