what is a reliable method for network weapons? (fps)

hey all, i’m looking for some insight on attaching weapons (or any usable item) to a player client.

i have tried this many (6) different ways so far, and every time some aspect fo the weapons do not function reliably, either they do not fire correctly, do not attach to the client skeletal mesh, or even appear to work in PIE but fail utterly in stand alone builds.

my latest attempt is very simplified, i have a replicated player pawn, weapon blueprints that inherit from a parent, then within the player i have a child actor component, in which i destroy the actor component and spawn a new one each time the weapon is switched. this method i chose as i suspect the errors i had perviously were a result of the weapon not having a specified ‘owner’?

at any rate, i am multicasting the switch weapon function which destroys and replaces the actor component of my child actor component on the pawn, and then use a blueprint interface to call the firing function, which appears to work correctly in some cases, but i also have a custom event on the weapon class that i can call from the player after using a cast (i suspect there are some issues with casting in Stand alone, which is why i am leaning away from them for now) so if i use the interface, the weapon fires correctly, and the projectile replicates, however the weapon is not attached to the skeletal mesh on the client ONLY, and i also do not appear to be able to access the controllers forward vector to launch in the correct direction.

if i use the custom event, i achieve much the same result, however the projectiles do not then replicate to the server, only visible on the client.

clearly this is a networking methodology issue, as well as potentially a core problem with the way i am approaching the problem.

I would be tremendously appreciative of anyone who cares to assist, i will be posting screens of my blueprints shortly, and i sincerely hope if i can get a helpful answer, i will respond expanding on where i went wrong and hopefully help others who share my misdirected understanding of networking in general.

p.s i have watched the blueprint networking tuts a number of times, and i DO realise there is something i am missing in them, no question.

Just a quick note: i implemented a controller reference in the interface which i pass to the weapon when it fires, using a reference to the player pawn’s controller, and now the weapons fire in the correct direction, however the projectiles do not appear on the server when the client fires.

Do you still need help with this?

Most assuredly, i put this one on the back burner becuase of mylack of success. Thankfully the intervening time has allowed me to develop my understanding of game frameworks much better so my next attemp wil be more ribust and effective.

Any advice is greatly appreciated.

So it seems your problem is mainly the gun not attaching to the mesh clientside? From memory, here’s the best way to handle the whole thing. This assumes you are using physics based projectiles (like in the FPS template) and that you want the bullets to exit the barrel.

a. On your mesh, create a socket where you want the gun to attach. This would probably be on the hand.

b. On your gun’s blueprint, add a primitive to handle collision.

c. On your character, make an on overlap event that triggers an attach actor to component. Attach the gun’s mesh to your hand socket. A Branch could also allow you to specify if there are preconditions to picking up the gun like pressing a key to equip.

d. Make a custom event on your gun called “fire”. Have it run on server.

e. Call the custom event “fire” on your character by pressing LMB or any key, really.

f. On your gun mesh, create a socket called “Muzzle” (do it a bit ahead of the model’s actual model to avoid possible collision problems). This is where bullets will exit.

g. Have “fire” execute a “spawn actor from class” function that spawns your projectile class. Make sure you also include a switch has authority node before the function. Server should have authority.

h. Feed in transform coordinates from a “get socket transform”. Feed in the mesh, and specify that it should be getting transform data from Muzzle.

That should be it. Only issue you might encounter is a problem with your gun’s transform not following your character animations. I’m still waiting for an answer on that one.