UE5

UE Multi Spawn Actor Replication

우대비 2023. 5. 4. 21:28
반응형

1. Server에서 Actor을 생성한 Location을 지정해준다

UFUNCTION(Server, Reliable)
    void SpawnEnemy();
    void SpawnEnemy_Implementation();
void AEnemyManager::SpawnEnemy_Implementation()
{
    int spawnIndex = FMath::RandRange(0, spawnPoints.Num() - 1);


    FVector tempPos = spawnPoints[spawnIndex]->GetActorLocation();
    tempPos.Z += 150;

    CreateEnemy(tempPos);
}

 

2. Multicast로 Client로 Location을 보내고 Client에서 Actor 생성

UFUNCTION(NetMulticast, Reliable)
    void CreateEnemy(FVector location);
    void CreateEnemy_Implementation(FVector location);
void AEnemyManager::CreateEnemy_Implementation(FVector location)
{
    AEnemy* enemy = Cast<AEnemy>(GetWorld()->
    	SpawnActor<AActor>(enemyFactory, location, FRotator(0, 0, 0)));
}

 

아래 영상을 보면 블루프린트로 설명하기에 쉽게 이해가 가능

위에 코드를 블루프린트로 구현한 영상

 

반응형
LIST

'UE5' 카테고리의 다른 글

“Cast of nullptr to AnimationBlendSpaceSampleGraph failed.”  (0) 2023.05.22
UE Multi Widget Interaction  (0) 2023.05.10
UE5 Multi SetTimer 안될때  (0) 2023.05.04
UE Multi Niagara Spawn  (0) 2023.05.03
UE Multi AnimMontage 동기화  (0) 2023.05.03