Download

Confused about actors in multiplayer

Hi,

Details of my setup. I have an replicated actor called LevelCreator in world that is supposed to run on server and spawn the replicated tile actors. What I thought is for each client I create will have its own LevelCreator.

This code is inside the DemoPlayerController that I created by extending APlayerController


void ADemoHexaGamePlayerController::BeginPlay() {
	for (TActorIterator<ALevelCreator> Itr(GetWorld()); Itr; ++Itr)
	{
		mLevelCreator = *Itr;
	}
	mLevelCreator->SetOwner(this);
}

Since I assumed that there will be one LevelCreator per client, What I expected this code to do is set Player controller in each client as owner to the LevelCreator inside that client.

Untitled-2.png

Like shown in image. This is my ideal situation. But the iterator is iterating through the all the LevelCreators’ and the owner of last LevelCreator is being set to last spawned Player Controller and all other LevelCreators and Player Controllers are just left out.

7e7cc22d345e29afa913a1259b87087c1d9e47cf.png

Since there are more than one LevelCreator its obvious that the last LevelCreator is owned by last player controller.

  1. Why is there more than one LevelCreator in scene?
  2. When I run dedicated server, in world details, the actors I see; Are they actors in client? or in server?
  3. If I want logic like initializing level by spawning tiles based on 2d array, where is it best to implement this logic?
  4. Is GameMode the place where I should be saving pointers to controllers and implementing game play logic?

(I don’t quite understand your setup)

Some question(s):
Why does each client need it’s own “LevelCreator”?

Have you tried spawning one LevelCreater for the server and use that to spawn the tile actors using a server side RPC?
You will probably need to store the LevelCreater in the GameMode for this to work.

HTH

This was my intention. I created a LevelCreator actor in level. And when I click play with 2 clients there are 2 level creators.
I think I’m doing it wrong. I just don’t know the right way of doing it.
How can I make actor spawn only in server?
Oh!!! Do you mean have a check for authority and spawn the actor runtime in begin play instead of putting it in level?

I think the only way to get this to work is to do a authority check on begin play in the LevelCreator and call destroy if it is not the server.

That is one possabality, But the method I mentioned before should achieve the same end resutl.

HTH