1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

UE5 ListenServer時のLevel移動(SeamlessTravel)についてのメモ

Posted at

Level移動時のパラメータの引継ぎ時にはまったことメモ

GameInstance

これでも渡せる

PlayerState

CopyPropertiesをOverrideして利用
CopyPropertiesで変数を受け渡す

SeamlessTravelした時にServerで呼び出される

Constructor→CopyProperties→BeginPlayの順で呼び出される

Client側では呼び出されないので同期する必要がある

CopyPropertiesは古い(遷移前のLevel)のPlayerStateで呼ばれる
引数が新しいLevelのPlayerState
何度か勘違いして時間を浪費しているので注意

コピーする際にポインタなどで保持しているパラメータは注意
古いものは破棄されるのでアドレスを保持していても破棄された状態になる

UPROPERTY(ReplicatedUsing=OnRep_ClassTest1)
UMyClass* MyClass = nullptr;

void APrototypePlayerState::CopyProperties(APlayerState* PlayerState)
{
    AMyPlayerState* NewMyPlayerState = CastChecked<AMyPlayerState>(PlayerState);
    NewMyPlayerState->MyClass = DuplicateObject<UMyClass>(MyClass, NewPS);

    // もしくはNewPlayerStateをOuterにして作成してから中身をコピーすればOK
    NewMyPlayerState->MyClass = NewObject<UMyClass>(NewMyPlayerState,UMyClass::StaticClass());
    // thisだと破棄される
    //NewMyPlayerState->MyClass = NewObject<UMyClass>(this,UMyClass::StaticClass());
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?