Hi, I’m trying to add components to an actor at runtime and then have them replicate.
The actor’s constructor:
ABuildingBlockGrid::ABuildingBlockGrid()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
SetReplicates(true);
}
And a function that is called on the server:
void ABuildingBlockGrid::SpawnBlock()
{
UBuildingBlockComponent* block = NewObject<UBuildingBlockComponent>(this, UBuildingBlockComponent::StaticClass());
block->RegisterComponent();
block->SetMobility(EComponentMobility::Movable);
block->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
block->SetWorldTransform(GetActorTransform());
block->SetMobility(EComponentMobility::Static);
block->SetNetAddressable();
block->SetIsReplicated(true); // <- Causes disconnection
}
This works fine in singleplayer, but it causes my clients to disconnect when “block->SetIsReplicated(true);” is called. If I don’t call it, my clients will be able to collide with it at the actor’s location, but not see it. What would be the proper way to do this?
EDIT:
I found the solution on the forum. Closing thread.