Last active
February 13, 2019 16:50
-
-
Save hach-que/23f9195f9c5d9cae7d2deae9a5ad9372 to your computer and use it in GitHub Desktop.
Game Manager for UE4 - Split code out from Game Instance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright Redpoint Games 2018, MIT Licensed. | |
#include "GameManager.h" | |
#include "Engine.h" | |
UGameManager::UGameManager(const FObjectInitializer& ObjectInitializer) | |
: Super(ObjectInitializer) | |
{ | |
} | |
void UGameManager::FinishDestroy() | |
{ | |
Super::FinishDestroy(); | |
} | |
UWorld* UGameManager::GetWorld() const | |
{ | |
UGameInstance* GameInstance = Cast<UGameInstance>(GetOuter()); | |
if (GameInstance == nullptr) | |
{ | |
return nullptr; | |
} | |
struct FWorldContext* WorldContext = GameInstance->GetWorldContext(); | |
if (WorldContext != nullptr) | |
{ | |
return WorldContext->World(); | |
} | |
return nullptr; | |
} | |
FTimerManager* UGameManager::GetTimerManager() const | |
{ | |
UGameInstance* GameInstance = Cast<UGameInstance>(GetOuter()); | |
if (GameInstance == nullptr) | |
{ | |
return nullptr; | |
} | |
return GameInstance->TimerManager; | |
} | |
FLatentActionManager* UGameManager::GetLatentActionManager() const | |
{ | |
UGameInstance* GameInstance = Cast<UGameInstance>(GetOuter()); | |
if (GameInstance == nullptr) | |
{ | |
return nullptr; | |
} | |
return GameInstance->LatentActionManager; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright Redpoint Games 2018, MIT Licensed. | |
#pragma once | |
#include "CoreMinimal.h" | |
#include "ObjectMacros.h" | |
#include "TimerManager.h" | |
#include "Engine/LatentActionManager.h" | |
#include "Engine/GameInstance.h" | |
#include "GameManager.generated.h" | |
/** | |
* The base class for game managers, which are persist objects that are capable of latent actions, similar to the game instance. | |
*/ | |
UCLASS(Transient, BlueprintType, Blueprintable) | |
class MINUTEOFMAYHEM_API UGameManager : public UObject | |
{ | |
GENERATED_UCLASS_BODY() | |
public: | |
//~ Begin UObject Interface | |
virtual class UWorld* GetWorld() const override; | |
virtual void FinishDestroy() override; | |
//~ End UObject Interface | |
FTimerManager* GetTimerManager() const; | |
FLatentActionManager* GetLatentActionManager() const; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment