Space Plunder
Loading...
Searching...
No Matches
PlayerStateComponentBase.h
Go to the documentation of this file.
1// Fill out your copyright notice in the Description page of Project Settings.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Components/ActorComponent.h"
7#include "PlayerStateComponentBase.generated.h"
8
9
10class APlayerState;
11
12UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
13class BASEHELPERS_API UPlayerStateComponentBase : public UActorComponent
14{
15 GENERATED_BODY()
16
17public:
18 UPlayerStateComponentBase();
19
20 template <class T>
21 T* GetPlayerState() const
22 {
23 static_assert(TPointerIsConvertibleFromTo<T, APlayerState>::Value, "'T' template parameter to GetPlayerState must be derived from APlayerState");
24 return Cast<T>(GetOwner());
25 }
26 template <class T>
27 T* GetPlayerStateChecked() const
28 {
29 static_assert(TPointerIsConvertibleFromTo<T, APlayerState>::Value, "'T' template parameter to GetPlayerStateChecked must be derived from APlayerState");
30 return CastChecked<T>(GetOwner());
31 }
33 // PlayerState accessors, only valid if called during gameplay
35
37 template <class T>
38 T* GetPawn() const
39 {
40 static_assert(TPointerIsConvertibleFromTo<T, APawn>::Value, "'T' template parameter to GetPawn must be derived from APawn");
41 return GetPlayerStateChecked<APlayerState>()->GetPawn<T>();
42 }
43 template <class T>
44 T* GetGameInstance() const
45 {
46 static_assert(TPointerIsConvertibleFromTo<T, UGameInstance>::Value, "'T' template parameter to GetGameInstance must be derived from UGameInstance");
47 AActor* Owner = GetOwner();
48 return Owner ? Owner->GetGameInstance<T>() : nullptr;
49 }
50 template <class T>
51 T* GetGameInstanceChecked() const
52 {
53 static_assert(TPointerIsConvertibleFromTo<T, UGameInstance>::Value, "'T' template parameter to GetGameInstance must be derived from UGameInstance");
54 AActor* Owner = GetOwner();
55 check(Owner);
56 T* GameInstance = Owner->GetGameInstance<T>();
57 check(GameInstance);
58 return GameInstance;
59 }
60
62 bool HasAuthority() const;
63
65 class FTimerManager& GetWorldTimerManager() const;
66
67protected:
68 virtual void BeginPlay() override;
69
70};
UCLASS(Blueprintable, BlueprintType, ClassGroup=(BucciGames), meta=(BlueprintSpawnableComponent)) class CHATSYSTEM_API UChatSystemComponent
Definition ChatSystemComponent.h:13