Skip to content

Commit

Permalink
Update code for 4.25
Browse files Browse the repository at this point in the history
- fixes references to AI code that was moved
- role authority was made private, fixed.
  • Loading branch information
Tom Looman committed May 13, 2020
1 parent a271401 commit 53df4ab
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CoopGame.uproject
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"FileVersion": 3,
"EngineAssociation": "4.17",
"EngineAssociation": "4.25",
"Category": "",
"Description": "",
"Modules": [
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
# C++ Multiplayer Third-person Shooter in Unreal Engine 4.

**Looking for a step by step guide?** I released my **[Unreal Engine 4 Mastery: Create Multiplayer Games with C++](https://www.udemy.com/unrealengine-cpp/?couponCode=TLGH14)!** Which includes two games teaching you C++, Networking for multiplayer and multiple AI including advanced behavior trees for ranged shooter AI.

Contains the project Source for the Udemy Course 'Unreal Engine 4 Mastery: Create Multiplayer Games with C++'.

Get the Udemy Course now and learn C++ for Unreal Engine 4: [DISCOUNT LINK](https://www.udemy.com/unrealengine-cpp/?couponCode=TLGH14)
Contains finished project for "Coop Game", part of the Udemy Course 'Unreal Engine 4 Mastery: Create Multiplayer Games with C++'.

**Originaly created with Unreal Engine 4.17, See Git Branches for updated versions**

**Important:** Check the "Branches" dropdown on GitHub for all supported Unreal Engine Versions! **(Supports: 4.18, 4.19, 4.20)**
**Important:** Check the "Branches" dropdown on GitHub for all supported Unreal Engine Versions! **Updated to 4.25**

![alt text](http://www.tomlooman.com/wp-content/uploads/2017/12/Thumb_MainUE4Course30_header.jpg)

Features

- Third Person Character
- Third-Person Character
- Shooter Weapon Code for hitscan and projectile weapons
- Custom AI 'tracker ball' like Gears of War that tracks and explodes near players.
- Power-up system including 'Health Regeneration' and 'Super Speed'
Expand All @@ -24,6 +20,8 @@ Features
- Custom ActorCompont for Health in any Actor like AI, Player, Explosive Barrel etc.
- UMG UI

Udemy Course Link: [DISCOUNT LINK](https://www.udemy.com/unrealengine-cpp/?couponCode=TLGH14)
**Looking for a step by step guide?** I released my **[Unreal Engine 4 Mastery: Create Multiplayer Games with C++](https://www.udemy.com/unrealengine-cpp/?couponCode=TLGH14)!** Which includes two games teaching you C++, Networking for multiplayer and multiple AI including advanced behavior trees for ranged shooter AI.

Get the Udemy Course now and learn C++ for Unreal Engine 4: [DISCOUNT LINK](https://www.udemy.com/unrealengine-cpp/?couponCode=TLGH14)

(Content in this project may only be used in Unreal Engine projects as per the Unreal Engine EULA)
2 changes: 1 addition & 1 deletion Source/CoopGame/CoopGame.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public CoopGame(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "NavigationSystem" });

PrivateDependencyModuleNames.AddRange(new string[] { });

Expand Down
19 changes: 10 additions & 9 deletions Source/CoopGame/Private/AI/STrackerBot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
#include "STrackerBot.h"
#include "Components/StaticMeshComponent.h"
#include "Kismet/GameplayStatics.h"
#include "AI/Navigation/NavigationSystem.h"
#include "NavigationSystem.h"
#include "NavigationPath.h"
#include "GameFramework/Character.h"
#include "AI/Navigation/NavigationPath.h"
#include "DrawDebugHelpers.h"
#include "SHealthComponent.h"
#include "SCharacter.h"
#include "Components/SphereComponent.h"
#include "Sound/SoundCue.h"
#include "EngineUtils.h"

static int32 DebugTrackerBotDrawing = 0;
FAutoConsoleVariableRef CVARDebugTrackerBotDrawing(
Expand Down Expand Up @@ -56,7 +57,7 @@ void ASTrackerBot::BeginPlay()
{
Super::BeginPlay();

if (Role == ROLE_Authority)
if (HasAuthority())
{
// Find initial move-to
NextPathPoint = GetNextPathPoint();
Expand Down Expand Up @@ -93,9 +94,9 @@ FVector ASTrackerBot::GetNextPathPoint()
AActor* BestTarget = nullptr;
float NearestTargetDistance = FLT_MAX;

for (FConstPawnIterator It = GetWorld()->GetPawnIterator(); It; ++It)
for (TActorIterator<APawn> It(GetWorld()); It; ++It)
{
APawn* TestPawn = It->Get();
APawn* TestPawn = *It;
if (TestPawn == nullptr || USHealthComponent::IsFriendly(TestPawn, this))
{
continue;
Expand All @@ -116,7 +117,7 @@ FVector ASTrackerBot::GetNextPathPoint()

if (BestTarget)
{
UNavigationPath* NavPath = UNavigationSystem::FindPathToActorSynchronously(this, GetActorLocation(), BestTarget);
UNavigationPath* NavPath = UNavigationSystemV1::FindPathToActorSynchronously(this, GetActorLocation(), BestTarget);

GetWorldTimerManager().ClearTimer(TimerHandle_RefreshPath);
GetWorldTimerManager().SetTimer(TimerHandle_RefreshPath, this, &ASTrackerBot::RefreshPath , 5.0f, false);
Expand Down Expand Up @@ -149,7 +150,7 @@ void ASTrackerBot::SelfDestruct()
MeshComp->SetVisibility(false, true);
MeshComp->SetCollisionEnabled(ECollisionEnabled::NoCollision);

if (Role == ROLE_Authority)
if (HasAuthority())
{
TArray<AActor*> IgnoredActors;
IgnoredActors.Add(this);
Expand Down Expand Up @@ -180,7 +181,7 @@ void ASTrackerBot::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

if (Role == ROLE_Authority && !bExploded)
if (HasAuthority() && !bExploded)
{
float DistanceToTarget = (GetActorLocation() - NextPathPoint).Size();

Expand Down Expand Up @@ -228,7 +229,7 @@ void ASTrackerBot::NotifyActorBeginOverlap(AActor* OtherActor)
{
// We overlapped with a player!

if (Role == ROLE_Authority)
if (HasAuthority())
{
// Start self destruction sequence
GetWorldTimerManager().SetTimer(TimerHandle_SelfDamage, this, &ASTrackerBot::DamageSelf, SelfDamageInterval, true, 0.0f);
Expand Down
2 changes: 1 addition & 1 deletion Source/CoopGame/Private/Components/SHealthComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ USHealthComponent::USHealthComponent()

TeamNum = 255;

SetIsReplicated(true);
SetIsReplicatedByDefault(true);
}


Expand Down
2 changes: 1 addition & 1 deletion Source/CoopGame/Private/SCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void ASCharacter::BeginPlay()
DefaultFOV = CameraComp->FieldOfView;
HealthComp->OnHealthChanged.AddDynamic(this, &ASCharacter::OnHealthChanged);

if (Role == ROLE_Authority)
if (HasAuthority())
{
// Spawn a default weapon
FActorSpawnParameters SpawnParams;
Expand Down
2 changes: 1 addition & 1 deletion Source/CoopGame/Private/SGameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void ASGameState::OnRep_WaveState(EWaveState OldState)

void ASGameState::SetWaveState(EWaveState NewState)
{
if (Role == ROLE_Authority)
if (HasAuthority())
{
EWaveState OldState = WaveState;

Expand Down
4 changes: 2 additions & 2 deletions Source/CoopGame/Private/SPickupActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void ASPickupActor::BeginPlay()
{
Super::BeginPlay();

if (Role == ROLE_Authority)
if (HasAuthority())
{
Respawn();
}
Expand All @@ -55,7 +55,7 @@ void ASPickupActor::NotifyActorBeginOverlap(AActor* OtherActor)
{
Super::NotifyActorBeginOverlap(OtherActor);

if (Role == ROLE_Authority && PowerUpInstance)
if (HasAuthority() && PowerUpInstance)
{
PowerUpInstance->ActivatePowerup(OtherActor);
PowerUpInstance = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions Source/CoopGame/Private/SWeapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void ASWeapon::Fire()
{
// Trace the world, from pawn eyes to crosshair location

if (Role < ROLE_Authority)
if (!HasAuthority())
{
ServerFire();
}
Expand Down Expand Up @@ -111,7 +111,7 @@ void ASWeapon::Fire()

PlayFireEffects(TracerEndPoint);

if (Role == ROLE_Authority)
if (HasAuthority())
{
HitScanTrace.TraceTo = TracerEndPoint;
HitScanTrace.SurfaceType = SurfaceType;
Expand Down

0 comments on commit 53df4ab

Please sign in to comment.