I am making data driven game
it is designed to level designer to write what should replicate and locate position by json file
like below:
{
“Name” : “BP_ABCD”,
“ShouldReplicate” : “true”,
“Location” : “X:111, Y:222, Z:333”
}
So, I want to turn on replication of actor after beginplay by data.
But
UE_LOG(LogTemp, Error, TEXT("AEventMultiListener::RegisterObject"));
TArray<AActor*> OutActors;
UGameplayStatics::GetAllActorsWithTag(this, FName(*ObjectName), OutActors);
if (UWorld* World = GEngine->GetWorldFromContextObject(GetWorld(), EGetWorldErrorMode::LogAndReturnNull))
{
for (FActorIterator It(World); It; ++It)
{
AActor* Actor = *It;
if (Actor->GetName().Contains(ObjectName))
{
UEventMultiComponent* NewEventMultiComponent = NewObject<UEventMultiComponent>(Actor, FName("EventMultiComponent"));
if (NewEventMultiComponent)
{
Actor->SetReplicates(true);
Actor->GetRootComponent()->SetIsReplicated(true);
NewEventMultiComponent->RegisterComponent();
UE_LOG(LogTemp, Error, TEXT("Succeed to spawn Event MultiComponent"));
}
else
{
UE_LOG(LogTemp, Error, TEXT("Failed to spawn Event MultiComponent"));
}
}
}
}
This code doesn’t look like it works.
Is it an illegal approach?
How should I proceed?