Unreal Tournament 4 Switch Weapon doubt

Hello, i’ve been looking into the UT 4 source code to see how switch weapon was handled and i noticed the following methods:

/** switches weapons; handles client/server sync, safe to call on either side */
 UFUNCTION(BlueprintCallable, Category = "Pawn")
 virtual void SwitchWeapon(AUTWeapon* NewWeapon);
 /** switches weapon locally, must execute independently on both server and client */
 virtual void LocalSwitchWeapon(AUTWeapon* NewWeapon);
 /** RPC to do weapon switch */
 UFUNCTION(Server, Reliable, WithValidation)
 virtual void ServerSwitchWeapon(AUTWeapon* NewWeapon);
 UFUNCTION(Client, Reliable)
 virtual void ClientSwitchWeapon(AUTWeapon* NewWeapon);

Shouldn’t ClientSwitchWeapon be NetMulticast to update all the other simulated clients that the weapon was switched? As it is, it should only run on the owner client (in this case the server) right? So how does he update the other clients?

The switch weapon functions are only for the server and client switching weapons to decide which weapon should be active. When the client switches to a new weapon it also destroys the existing weapon actor and spawns a new one. That is the update the other clients see. They don’t need to know what weapon the other client has active because they don’t need to control them. All they need to know is where other characters are and what they should look like.

Look for AUTCharacter::UpdateWeaponAttachment()

Wouldn’t this be better off on the Unreal Tournament forums?

It seems to me like this is a how and why question suitable for the C++ forums not some kind of bug report or suggestion for Unreal Tournament development. UT is a great resource for learning the engine seeing as its made by the folks making the engine.

Yes james0x0A, unfortunately UT is currently the best resource to learn C++ and networking, Shooter Game is not bad, but it isn’t the best either because it’s missing a lot of stuff. So from what i understand, the other clients are only updated because you destroyed and recreated the weapon on the server, which is automatically replicated without doing anything, right? I always had the doubt if i should run minimal logic for the other clients (only play animations and do blindly what the server tells without checking if values or states are correct) and run a more complex logic for the current player and the server OR simply make them all run the same logic for simplicity sake. For example, i want to equip a weapon, should it follow the workflow:

1- Player pressed the 2 key to equip a weapon
2- The Autonomous Client runs the function EquipWeapon checks if we need to play first the unequipping animation, if not, it executes StartEquippingWeapon.
3- This method uses PlayAnimMontage to play the equip animation and SetTimer for the duration of the animation and then executes FinishedEquippingWeapon, which has the finishing logic.
3- When the client is starting the animation it sends a ServerEquipWeapon for the server to run the same logic.
4- When the server is starting the animation it sends a NetMulticast function for all other clients to execute this logic so they are all in sync (this will also execute on the Autonomous Client, but it will not run because bIsEquipping is true and he will return immediately)

Which workflow should i choose for a real network game?

Please post this question to the Answer Hub:
When you do, include a link to this post.


Answer Hub Link

P.S: When should i post on the forum or the Answer Hub?

Is this a suggestion for more exposure or are you telling him the question doesn’t belong here?