Additional instructions for later versions of Unreal

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 the AGun::AGun() constructor
  • if(bUsingMotionControllers) { ... } from AFirstPersonCharacter::BeginPlay() to AGun::BeginPlay()
    Note: Comment out both the Mesh1p-> accessors from this if 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!

7 Likes

Hey Dude,

Thank you for your time and effort on this, it really helped out =]

Kind regards,

Dominic

A big thanks for taking the time and posting all of this.
I would not have gotten it if it wasn’t for you to much over my head yet.

thanks again

I’m having these errors , can u help please?

https://api.unrealengine.com/INT/API/Runtime/HeadMountedDisplay/UMotionControllerComponent/index.html

https://api.unrealengine.com/INT/API/Runtime/HeadMountedDisplay/UMotionControllerComponent/SetTrackingSource/index.html
So something like R_MotionController->SetTrackingSource(EControllerHand::Right);

Or you can just delete those lines, since you’re not using VR controllers anyway.

Just finished refactoring my code for version Unreal Version 4.22, here is my repo commit link:

1 Like

Thank you so much for this! this definitely reduced a lot of confusion in getting through this lecture.

I am on v4.19.2, and because of this there was an extra line or two that i had to adjust. here is my code in the latest commit:

FirstPersonCharacter.h
FirstPerson.cpp
Gun.h
Gun.cpp

**In my Visual Studio 2017 file the Mesh1p lines in the constructor are highlighted as an error, but when compiling this does not seem to be an issue so if anyone has anything similar just thought i’d share…

1 Like

Struggled for 3 hours in 4.14.3 - I want to stick as close to the engine version in the video and had some interface problems with 4.12/13. Anyways, I decided to copy/paste OP’s code. To anyone else doing this, some things to note. He has named his project different to the video. His gun.h has:

class TESTINGGROUNDS_API AGun : public AActor

as opposed to the video:

class S05_TESTINGGROUNDS_API AGun : public AActor

I had to comment out the nested loop of EnableTouchscreenMovement (pic related). Also his .h files have multiple instances of public/protected which I merged with no problem. I may have missed something as I am a bit frazzled, so it’s time for a cup of tea before the next battle. Thank you to OP & ktonegawa.