Seeking guidance on setting up game structure for VR motion controlled vehicles

I’m at a stage in my game development where I have a vehicle pawn, another VR pawn, and I’m trying to work out a good system for setting up a game mode, player controller, spawning the vehicle, getting the vehicle to work with various input mapping contexts, etc.

My requirements are that I can run the game in VR with motion controllers which affect the vehicle, or alternatively, in flatscreen mode with mouse and keyboard (really just for debugging or further prototyping of systems).

Currently in my vehicle blueprint, I’m casting to the VR Pawn (which is the default pawn), and attaching the VR Pawn’s camera to a scene location on the vehicle. I never have to hop out of the vehicle or anything so there’s no real need for anything on the VR Pawn other than the motion controllers and camera. This works ok.

My confusion/uncertainty is really around the order in which various things spawn in the game - including the player controller, game mode, the VR and vehicle pawn, and how these objects should interact and where to add various functionality. I got caught out last night trying to access a variable from the player controller in the vehicle blueprint on event ‘beginplay’, and realised that the vehicle was actually being instantiated before the player controller was and therefore the variable hadn’t properly been set yet. The vehicle blueprint was manually dragged into the scene and was not being spawned in blueprint code anywhere, so I guess this is the reason.

So… I’m looking for a good convention or example, etc, to setting things up in a modular way. What should my game mode do? In which blueprint should I set a global variable which tells me whether I’m in ‘VRMode’ or not? In which blueprint should I spawn a vehicle? Should I put input functionality into a player controller, VR pawn, or vehicle pawn? Is it ‘wrong’ to have two pawns (vehicle and VR), and should I combine these things into one? But then if I do, I will need to do the same for other vehicles down the line (I am now adding the same VR functionality for additional vehicles). Which seems not ideal.

I’m sorry if this sounds too broad- I’m not really looking for an answer to a question, but to get a feel for what experienced people might do in this situation. I don’t want to get fancy with things, I just want a nice, flexible, clean system…

Am I in VR mode? OK- here’s your motion controls and your VR Input mapping context. Also, don’t run VR specific vehicle functions on tick.

Not in VR mode? OK- set the input mapping context to non VR, create a debug info HUD, etc.

Any guidance would be very appreciated :slight_smile:

Cheers!

Claude AI suggests:

// Game startup flow:

1. GameMode BeginPlay

    • Set IsVRMode*
    • Setup initial state*

2. PlayerController BeginPlay

    • Get IsVRMode from GameMode*
    • Setup appropriate input context*

3. GameMode SpawnVehicle

    • Spawn vehicle blueprint*
    • Pass initial setup parameters*

4. Vehicle BeginPlay

    • Get IsVRMode from GameMode*
    • Setup appropriate components*
    • Initialize input handlers*

Also suggests a single vehicle pawn with VR capabilities:

Vehicle Pawn Begin Play / construction script:
- Get IsVRMode from GameMode
- IF VRMode:

    • Create VR Camera Component*
    • Setup VR-specific attachments*
    • Enable VR-specific functions*
      ELSE:
    • Setup regular camera*
    • Enable debug features*

// Implement separate functions for:
HandleVRInput()
HandleNonVRInput()

How does this all sound?