Edit: My bad, I see now you’ve already posted this.
Also, I see your weapon is an actor. Is your weapon class marked for replication? Is your player class marked for replication too?
AWeapon::AWeapon()
{
SetReplicates(true);
}
If you’ve checked the above and you are certain the weapon change function is being executed on server, try this. Perhaps, for some reason, your character or weapon actors aren’t deemed “relevant” yet for replication. The server sometimes holds back sending a change in value for actors that are far away from the local player. Try setting your player class’ and weapon class’ bAlwaysRelevant = true in their constructors. If that makes a difference, then you know your issue is related to network relevancy. However then you should try to find out why the server deems the actor irrelevant, using bAlwaysRelevant = true isn’t a neat long term solution for physical actors.
That’s too bad. It was unlikely that network relevancy would cause your issue but its always good to check just to be certain.
I just noticed you try to call an RPC in your weapon class. Are you sure the server actually executes the RPC? For a client to be able to call a server RPC, the server must set that actor’s owner to that client’s player controller. By default you are able to call server RPCs on your pawn and player controller (and player state perhaps) because the game mode code sets this up, but for other actors you have to set the actor’s owner yourself using SetOwner(). So if Weapon is your AWeapon instance and PC is the player’s controller:
Weapon->SetOwner(PC);
So if you haven’t made sure, make sure that calling ServerFire() actually executes on the server. If not, do the above.
You mean on the Player::CurrentWeapon variable? I guess there’s no need, since I use DebugMessages to check which is the value of that variable at a given time.
When I switch among weapons normally (by pressing the key associated with a specific weapon), it works perfectly. The weapon switching always works perfectly.
But when I call the ForceWeaponSwitch(), from the Weapon class, the function is executed but the value of the variable not changed.
(As a reminder, on the server listener window this works!)
You need to update the clients variable from the server variable, using event tick, then update all variables. To do this, the variables must be replicated
Also, I don’t understand very well your suggestion. If I change a variable for a specific client ON THE SERVER, it should succeffully change (as it happens with all variables, but the Weapon*)