How exactly is the AI Controller only existing on Server?

How exactly is the AI Controller only existing on Server?
I know its by design. But I would like to understand how it is so?

I don’t see ‘bReplicates=false’ in the AIController constructor. So what makes it so that the AI Controller doesn’t exist on the client?

Does this apply to any actors that are spawned by the Server and the actor has ‘bReplicates=false’ set?

Does one require to have ‘bReplicates’ set to false to guarantee that the actor only exist on server? Or is there another way to make sure the actor only exists on Server?

To be precise AI Controllers only exist on the server in networked games. The Player Controllers exist on the server and also on the controlling client’s machine. Player Controllers don’t replicate either, except to the server. PlayerController and AIController inherit from AController, which only replicates PlayerState and its controlled Pawn. AI Controller does not have any replicated properties of its own. Normally an AI Controller does not have PlayerState, so it is only replicating its pawn. If you override the default behavior of AIController in C++ so that it has a PlayerState, then it would also replicate the PlayerState when AController does its GetLifetimeReplicatedProps.

Okay. I understand that the replicated data is being done via a player state.

But my question is that how is a player controller actor created on the client and also on the server?
But the AI controller is only created on the server.

I am trying to make sure my custom class actor is only spawned ever on a server.

There are a few different concepts to understand but most important are the actor’s Role, RemoteRole and bReplicates, because those are the key components. If you just want to make an actor (like AAIController) that doesn’t replicate and doesn’t have an autonomous proxy, then set the AActor’s bReplicates to false, Role to ROLE_Authority and RemoteRole to ROLE_None when spawning the actor into the level on the server. These happen to be the default settings of the AActor class.

To understand how a Player Controller works, you’d have to learn about roles and proxies.

The default model used by Unreal Engine is server-authoritative, meaning that the server always has authority over the game state, and information will always replicate from the server to clients. You would expect an Actor on the server to have a Local Role of Authority, and you would expect its counterparts on remote clients to have a Local Role of either Simulated or Autonomous Proxy.

Read the documentation here: Networking Overview for Unreal Engine | Unreal Engine 5.3 Documentation
Check out the section on Network Role and Authority.

1 Like

Because the Controller base class is only relevant to the owner of the Controller.

	bOnlyRelevantToOwner = true;

If the controller has no Player Owner then it never gets replicated.

1 Like