Who or what assigns the roles to the objects?

Roles are important for branching game logic based on networking, I’ve seen that you can actually set the values of role as a integer constant.

So when a game starts what decides what an objects role or remote role would be? e.g who sets that pawn must get Simulated_Proxy ?

Is it set in the constructor and then respected in the rest of the code to make that behavior since the role does not directly define the replicative properties.

Looks like at the core of an Actor (found in Actor.cpp) the default value is set to ROLE_Authority.

But, if you look at ActorConstruction.cpp you can see a nice little code snippet here:


		// Exchange net roles before running construction scripts
		UWorld *OwningWorld = GetWorld();
		if (OwningWorld && !OwningWorld->IsServer())
		{
			ExchangeNetRoles(true);
		}

This indicates that the World Context of an object determintes it’s role in a server. Usually though, it seems objects placed in the world via the editor and are not replicated, are owned on the client. However, if the actor is spawned on the server, the server owns it, or if it is spawned on the client, the client owns it.

To find out more, I would look more into the following files of the source:

Actor.h / .cpp
ActorReplication.h / .cpp
ActorConstruction.h / .cpp

For a good start.

And if you haven’t already, read up here:

https://docs.unrealengine.com/latest/INT/Gameplay/Networking/Actors/Roles/index.html
https://wiki.unrealengine.com/Replication