XYZ

Devlog 4 - Client Inputs and Server Processing

So this is going to be a shorter post, but I just wanted to give a quick outline on how I'm handling client to server communication specfically for inputs.

First how do we handle client to server communication using UE5? It's actually quite simple on the outside Unreal let's us declare certain function on our PlayerController class that are designated to be RPC Calls

UFUNCTION(Server, Reliable)
void QueueInput(const FXYZInputMessage& InputMessage);
void QueueInput_Implementation(const FXYZInputMessage& InputMessage);

Assigning a UFUNCTION to be Server means that when this function is called on the client it will be executed on the remote server. Making it quite easy to send a payload of information from our client to the server on every input.

I created the payload as a Struct called XYZInputMessage and it looks as follows

struct FXYZInputMessage
        FString PlayerId;
        TArray<int32> SelectedActors;
        int32 XYZTargetActor;
        FVector TargetLocation;
        EXYZInputType InputType;
        bool bQueueInput;
        int32 AbilityIndex;
        int32 ActiveActorId;

When the QueueInput function is executed on the remote server it then passes it along to the server's InputManager which is processed every tick InputManager->QueueInput(TickInput);

The InputManager every process goes through it's InputQueue and executes inputs that are valid

void Process(float DeltaTime)
{
    for(;InputQueueIndex < InputQueue.Num();InputQueueIndex++)
    {
        ExecuteInput(InputQueue[InputQueueIndex]);
    }
}

But what do these inputs turn into? Well every Input that a client does that the server needs to know is turned into an XYZAction in our not so pretty XYZActionFactory

The factory takes in an InputMessage and spits out one of the many actions

These actions are passed onto our blobs (group of units structure) which then processes the actions.

Here's a beautifully drawn diagram to show the flow

XYZ

Thanks for reading!

View original