unreal engine 5.2 c++ 自定义gameplay

1. 新建c++工程

image

2. 打开world setting

image

3. 修改默认GamePlay

image

4. 依次新建对应GamePlay替换默认GamePlay

image

Default Pawn

image

UCLASS()
class HELLOGP_API AHelloPawn : public APawn
{
    GENERATED_BODY()
}

HUD

image

UCLASS()
class HELLOGP_API AHelloHUD : public AHUD
{
    GENERATED_BODY()
};

PlayerController

image

UCLASS()
class HELLOGP_API AHelloPlayerController : public APlayerController
{
    GENERATED_BODY()
};

GameState

image

UCLASS()
class HELLOGP_API AHelloGameStateBase : public AGameStateBase
{
    GENERATED_BODY()
};

PlayerState

image

UCLASS()
class HELLOGP_API AHelloPlayerState : public APlayerState
{
    GENERATED_BODY()
}

SpectatorPawn

image

UCLASS()
class HELLOGP_API AHelloSpectatorPawn : public ASpectatorPawn
{
    GENERATED_BODY()
};

GameInstance

/** Please add a class description */
UCLASS(Blueprintable, BlueprintType)
class UBP_HelloGameInstance : public UGameInstance
{
    GENERATED_BODY()
};

5. 添加AHelloGameModeBase默认构造函数

image

#include "hellogpGameModeBase.h"
#include "HelloGameStateBase.h"
#include "HelloPlayerController.h"
#include "HelloPlayerState.h"
#include "HelloHUD.h"
#include "HelloPawn.h"
#include "HelloSpectatorPawn.h"

AHelloGameModeBase::AHelloGameModeBase()
{
    GameStateClass = AHelloGameStateBase::StaticClass();
    PlayerControllerClass = AHelloPlayerController::StaticClass();
    PlayerStateClass = AHelloPlayerState::StaticClass();
    HUDClass = AHelloHUD::StaticClass();
    DefaultPawnClass = AHelloPawn::StaticClass();
    SpectatorClass = AHelloSpectatorPawn::StaticClass();
}

6. 编译看效果

image

posted @ 2023-06-23 15:03  BuzzWeek  阅读(40)  评论(0编辑  收藏  举报