How to use AI on Client Side in Network game ? (without replication)

Hello :slight_smile:

Description:
I am trying to control a AI on the Client side only using the inbuild capabilities of the Engine.

More specifically, I have an actor that need to use the PerceptionSystem. My actor does not have controller and has the following components attached; UAIPerceptionStimuliSourceComponentand UAIPerceptionComponent

It works fine on the Server Side (Listen Server) where Actors can perceived other Actors (sight) but on Client Side, no one can perceived no one …

What I found:

  1. The PerceptionComponent needs a UAIPerceptionSystem and a UAISystemBase to works
  2. Neither of UAIPerceptionSystem nor UAISystemBase seem to exist on Client Side
  3. UAISystemBase seem to be instanced here: UWorld::CreateAISystem()
  4. The condition to be instanced looks like:
if (AISystem == NULL && UAISystemBase::ShouldInstantiateInNetMode(GetNetMode()) && PersistentLevel)
  1. The declaration and implementation of the fonction are:
static ENGINE_API bool ShouldInstantiateInNetMode(ENetMode NetMode);

bool UAISystemBase::ShouldInstantiateInNetMode(ENetMode NetMode)
{
	UAISystemBase* AISystemDefaultObject = Cast<UAISystemBase>(StaticClass()->GetDefaultObject());
	return AISystemDefaultObject && (AISystemDefaultObject->bInstantiateAISystemOnClient == true || NetMode != NM_Client);
}
  1. And finaly I found inside UAISystemBase
	/** Whether the AI system class should be spawned when connecting as a client */
	UPROPERTY(globalconfig, noclear)
	bool bInstantiateAISystemOnClient;

So this looks like what I want but how to set the value at TRUE ? (without modifying the Engine..)

Note: ShouldInstantiateInNetMode is not virtual, so I cannot override it and bInstantiateAISystemOnClient is private.
Note2: I think it is on the config file DefaultEngine.ini to add:

[/Script/AIModule.AISystem]
bInstantiateAISystemOnClient=True

But it does not seem to work so I need a confirmation that it is the solution or not before continuing to dig …

Thanks a lot! :smiley:

can i ask why you’d want the client to control an AI? keeping in mind that even if it worked it would desync from server?

Hello @Auran131 ,

Yes of course !

I am making a RTS game and to save bandwidth (among other things), I an trying to use a deterministic lockstep architecture :slight_smile: (without rewrite all the engine code …)

I only send input to others players and the simulation should be exactly the same on Client and Server side (So I need the perception system working on both side).

Thanks!

Variable is “globalconfig” so you need to use the class it’s declared in

[/Script/Engine.AISystemBase]
bInstantiateAISystemOnClient=True
2 Likes

Hello,

Thanks! It works like a charm :slight_smile: