UE4 BatteryCollector C++ Tutorial Upgrade from 4.9 to 4.18

If you’re like me and is new to both C++ and Unreal Engine 4, but is an experienced programmer and decide to dive right in to developing UE4 games with C++, you will see your only official option for a full-game tutorial series is the BatteryCollector.

But these tutorials were made in UE4 version 4.9, and a lot of breaking changes have happened since then.

I’ve gone through quite a bit of a headache following the tutorials, and so you don’t have to I’m listing the differences needed on your part to make it work with 4.18.

Download source files on GitHub.

In SpawnVolume.h:
#include "Components/BoxComponent.h"

In SpawnVolume.cpp:
#include "Runtime/Engine/Classes/Engine/World.h"
#include "Runtime/Engine/Public/TimerManager.h"

In BatteryPickup.cpp:
#include "Components/StaticMeshComponent.h" (we don’t need it in the header)

In BatteryCollectorCharacter.cpp:
CollectionSphere = AttachTo(RootComponent); should be CollectionSphere->AttachTo(RootComponent); this was fixed in tut10
#include "Runtime/Engine/Classes/Components/SphereComponent.h"

In BatteryCollectorCharacter.h:
The UPROPERTY macro category for CollectionSphere should be something other than “Camera”, as it is not a camera. I used “Collection”

In BatteryCollectorGameMode.cpp:
1. Add PrimaryActorTick.bCanEverTick = true; to the constructor, as Ticking is now false by default.

2. #include "Runtime/Engine/Classes/GameFramework/PawnMovementComponent.h"

In BatteryCollectorGameMode.h:
1. Make enum class derive from uint8 as such: enum class EBatteryPlayState : uint8 {};
2. Make sure to use MyCharacter->GetCurrentPower(), NOT MyCharacter->GetCurrentPower in game mode tick function for changing play state.

In ThirdPersonCharacter Blueprint Event Graph:

Download source files on GitHub.

Leave a Reply