I’m following along on this course with a later version of Unreal (v4.18.1), which means that the FirstPersonCharacter class has a few extra bits in it revolving around VR. This means that to successfully seperate the gun logic from the FirstPersonCharacter class, a little bit more manipulation is needed! Here are the necessary additional steps needed to bring parity to Sam’s current project state:
Move the following variables from FirstPersonCharacter.h to Gun.h
-
VR_Gun
(default protection) -
VR_MuzzleLocation
(default protection) -
R_MotionController
(default protection) -
L_MotionController
(default protection) -
bUsingMotionControllers
(public protection)
Move the following code from FirstPersonCharacter.cpp to Gun.cpp
#include "Kismet/GameplayStatics.h"
#include "MotionControllerComponent.h"
- Every line of code in the
AFirstPersonCharacter::AFirstPersonCharacter()
constructor from
// Note: The ProjectileClass and the skeletal mesh/anim blueprints for Mesh1P, FP_Gun, and VR_Gun
inclusive, to the end of the constructor - this should be placed in theAGun::AGun()
constructor -
if(bUsingMotionControllers) { ... }
fromAFirstPersonCharacter::BeginPlay()
toAGun::BeginPlay()
Note: Comment out both theMesh1p->
accessors from thisif
statement.
Here’s links to the files so you can see the changes which hopefully makes it more obvious!
Note: I’ve kept the files as close to Sam’s as possible, so there’s code in there that perhaps shouldn’t be (GunOffset
in the FirstPersonCharacter.cpp comes to mind), but I’m assuming that things like this will be addressed in later lectures. All in all, this should be a good foundation to work from going forwards.
After creating the Gun blueprint class, you will also need to setup the VR_Gun
and VR_MuzzleLocation
components in a similar way to that of their respective FP_Gun
and VR_MuzzleLocation
components. Verify that the L_MotionController
is set to the Left hand in the details pane, and the R_MotionController
is set to the Right hand. I don’t have access to VR equipment, so I can’t verify if these are the only steps necessary to configure these components, but fi you want more information, then there’s a great article from Unreal on the subject!