RPC function vs RoleAuthority check?

bEnabled is not a variable to be changed for everyone. If I activate my weapon, only my weapon->isEnabled must be actived, not everyone’s.

So putting it on a logic perspective, I’ve made a SERVER-RPC call in the Weapon class, in a manner that only the server will set the variable on the owning client:

Result:

the ServerRPC function doesn’t get called, because I see that the DebugMessage put inside that function is not called.
I see the one inside the Enable() function, but not the one in the RPC function.

[ignore the attachement image below]

The Client must own the Weapon for ServerRPCs to function.

If you scroll down that side, you can find tables with when RPC’s work and when they are dropped.

I would say, you haven’t specified the Client as Owner of the Weapon when spawning it. So that’s why the
RPC is just dropped. Use the Clients PlayerController (on the Server!) as an Actor for the Owner of the Weapon when Spawning.

Documentation about Ownership: Actors and their Owning Connections | Unreal Engine Documentation

Ok, I’ve set my Character as the Owner of the weapon being spawned and it now works. ( <— this was the problem by the way, not the ServerRPC function )

I can finally get my weapon-enabling work!

The problem is that when the game starts, the client doesn’t equip the Pistol automatically (as I told him to do).
If I manually press the button to EquipPistol(), at that point it works.

But If I EquipPistol() in the PostInitializeComponents() -> InitializeInventory() it doesn’t work.

It’s like it should take some time. It didn’t take much to set my character as owner, why isn’t it able to EquipPistol() quickly?

How could I manage this in a multiplayer game where, as soon as you click “Join Match”, you must spawn with your inventory without any annoying delay?

You might wanna try moving the Inventory call to BeginPlay instead of PostInitComponents.

And, for some reason, the ShooterGame puts a ServerRPC call when equipping a weapon.
Since the weapon equip is something fired by the client when he presses a button, they call the EquipWeapon() from the client and execute on the server.

Why? How could leaving the client equipping the weapon have been a possible cheat?

(I tried and that didn’t work for me, by the way)

My bad… I wasn’t replicating the CurrentWeapon…

[COLOR=“#FF0000”]FACEPALM[/COLOR]
11.png

Ok now I have another little issue. When I shoot with the weapon, I want a little Point to appear so that I know where I shot the bullet.

1.jpg

HitResult is a variable modified by a static function called Trace, you can see it here A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums

The problem is I see the DebugPoint on the server, but not on the client.
I made sure the HitResult variable is replicated, but no luck here.

With a NetMulticast it works fine, but is this the best way to do it?
@eXi

Well, your function is only called on the Server. You “return” when a client calls it. So it’s pretty normal, that only the Server sees the impact point.
Yes, a multicast could do it for the time.

Normally you let Server AND Client shoot. But only the Server will register Hits for Damage. Then the Client also has HitResults to work with, which
he can use to spawn decals and stuff.

The Shoot of the player is an input, and so is called on the client.

When I do this:

f916af3f297e68e08cbcdd774bb4a8436930a748.jpeg

It means that the client-part of the Character should call the Server for all the important stuff (ServerStartFire) and after that, the Client-part of the Character MakeDecal()

Well, in the Server Window I can’t Make the Decal, since it’s a server. But didn’t every player in the game have both a client and a server part incorporated?

Because even if the ServerWindow is the Host-Server of the session, but don’t forget it’s also a client playing the game!

Why “for the time”? The decal image on a wall after shooting on it should be seen by everyone in the game.

“For the time”, because you shouldn’t multicast hit results. That’s overdoing it.
Server AND Client should shoot. And both get their HitResults. And the Client uses his HitResults to
draw effects, the Server also does this if he’s the ListenServer + handling Damage when a line trace hits something.

Check out the ShooterGame if you want to learn a bit more about creating Replicated Weapons in C++.

1 Like

I followed your suggestion:



/* START FIRE (called by the Character when presses the LeftMouseButton to fire) */
void AWeapon::StartFire(AMyCharacter* Shooter)
{
        // Both server and client part
	bool bHitSomething = PerformTrace(Shooter);
	MarkDecal();

	// SERVER PART 
	if(Role == ROLE_Authority)
	{
            // damage... death... life... ALL IMPORTANT STUFF
	}
	
}


BUT, as said before, the draw effects must be visible for everyone, not just for the player who shoots.

This means that If the Client shoots, the Server sees nothing and vice versa.

So, you call “StartFire” on the Client and the Server via an RPC in the Character?
Because if yes, then Server and the Client should be able to see the Decal.

And yes, if you need them on ALL clients, then you need a Multicast, although Epic Games does this with
a RepNotify variable. As i said, you kinda wanna check out the Weapon in the ShooterGame (:

AWeapon::StartFire() is called by the client, since in the Character I bind an action for the LeftMouseButton that calls CurrentWeapon->StartFire()
Since there are things to be managed by the Server (like damage handling) I made a ServerRPC function.

Very simply, all this ServerRPC function does is performing a RayCast and storing the HitResult in a replicated variable.
After the HitResult is filled, the Server calls a NetMulticast RPC function that makes everyone know where the bullet went.

The only bug I now find in all these stuff is the one I described into detail here Serious shot replication problem [video] - Multiplayer & Networking - Epic Developer Community Forums, please check it out.

The ShooterGame is full of things I don’t even need, and these things get mixed with the ones which I really need. Dunno if it makes sense.

Going through it all requires even more time, time I can’t really afford. Can’t afford because I’m alone, and other than studying programming for years, I’m forced to study how Networking works in UE and also I’m studying 3D Modeling, Rigging and Animation… all these things together, since this is a one-person “team” based project.

Asking in the forum is the best alternative and the only way to speed up my work a little bit.

I’m very sorry to steal your time, but after years and years spent learning computer science and computer programming, I end up with an Engine that also requires to study its way of doing things.
It’s a bit frustrating, but I guess I can rely on the Unreal Engine Forums Community :slight_smile: