unreal engine 5.2 c++ 自定义gameplay

发布时间 2023-06-23 15:07:48作者: BuzzWeek

1. 新建c++工程

image

2. 打开world setting

image

3. 修改默认GamePlay

image

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

image

Default Pawn

image

HUD

image

PlayerController

image

GameState

image

PlayerState

image

SpectatorPawn

image

5. 添加AhellogpGameModeBase默认构造函数

image

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

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

6. 编译看效果

image