Weapon Actor visibility/replication question

Hello,

I’m trying to set up a simple multiplayer FPS, and am running into an issue regarding weapon visibility between first/third person and different clients. I’m fairly new to messing around with replication so I suspect the answer to my issue might be simple, but after a couple of days of trial and error mixed with exhaustive searching, I’ve been unable to solve it or make any meaningful progress, so I thought I would ask here and see if anyone can point me in the right direction.

My weapons are set up as actors, child classes of “BP_WeaponMaster”. I have one that gets attached to my first person arms, and one that gets attached to the equivalent place on the third person version of the character. Dealing with character visibility has been fairly simple - just a matter of correctly setting Only Owner See/Owner No See on the skeletal meshes of the character blueprint. I’m having a tough time figuring out how to achieve the same thing with the weapon actors, which are created on BeginPlay with Spawn Actor from Class and then attached; setting the owner of the weapon actor to my character BP and then looping through the meshes in the weapon actor to set Only Owner See/Owner No See didn’t seem to have any effect at all.

Would anyone be able to explain to me the correct way to have each player see only their first person weapon actor, and only see the third person weapon actor of other players?

Any help on this would be much appreciated, and thanks in advance!

what your doing sounds correct, id check if the ownership is set correctly on the weapon BP, also when you spawn on begin play make sure only the server is spawning with a switch has authority, its possibly you have duplicates spawning on client side

Hi, thanks for the reply! I messed around with an authority switch but wasn’t able to get any meaningful results. I had a print string from the Get Owner node that I’m using to set the weapon BP’s owner, and it returns two separate strings for the two separate players, so I’m pretty sure at least in principle that works. I’m 100% sure that this issue is related to me being a newbie at replication, and that I’m doing something glaringly wrong, or else not doing something that I should be. I’m going to add a few images of my nodes and the result, hopefully someone can point out what that missing element is or correct my understanding here.

So here is where the action starts, in BeginPlay:

The “Init Weapon” function starts off like this:

if I stop after Attach Actor To Component, then in game both players have their own weapon visible, and can also see each other’s weapon. So, I go one step further and add the following, circled in red:

When I do this, and then hit Play, for some reason the Listen Server player ends up seeing neither his own, nor the client’s weapon, while the client sees both. Presumably the client is ending up as the owner of both weapon actors but I cannot understand why that would be the case:

If somebody could take me to school on this I would really appreciate it because it’s driving me up the wall! Fiddling with this further, I even managed to get it to the point where each player could see the other player’s weapon, and not his own; the complete inverse of what I was aiming for, despite using Only Owner See!

I’m sure this is just me completely misunderstanding replication on some level and I would love to know how/where.

I think you are replicating the weapon reference and not the weapon actor…
Do the second.

Hi Ivan3z, thanks for taking a look!

I have my weapon actor’s replication settings set to the same as what you posted in your screenshot. I also think the weapon actor is replicating correctly because if I disconnect the loop (setting the Only Owner See variable circled in my third screenshot) then all the weapon actors are present for each player. It’s only when I go the extra step and try to make other players’ weapons invisible using the Only Owner See bool, that the server cannot see his or anyone else’s, while the client sees them both. I think the weapon is still there logically even after this, because the server player’s left hand is in the correct position still even though the weapon isn’t visible - so the socket the IK is looking for must be present, which means the weapon actor and it’s mesh must be there also, just hidden.

You can attach the camera to the weapon… that’s all… you don’t need more…
Why are you hiding the weapons?

I want my first person view/weapon to be separate from it’s third person counterpart. I will do gameplay-related things from the FP weapon, while the TP weapon will just be visual for other players - no projectiles or anything gameplay relevant will be coming from it. The locations of the two, their animations etc, will not necessarily line up exactly - just close enough to not be noticeable. This means that I need to control which player is seeing which weapon actor, based on ownership.

A player from his own perspective should see only his first person weapon actor, and his third person weapon actor should only be visible to others looking at him. It’s the same concept as hiding the skeletal mesh FPS arms from other players, and instead having them see a full body mesh that the owner of that full body does not see himself. The only difference is that my weapon is a separate actor and I seem to be having trouble setting its network ownership correctly, so that Only Owner See/Owner No See work on it’s components the same way as it’s currently working for the full body/FPS arms meshes that are components of the character BP.

In the screenshots above I am only dealing with the first person weapon actor; once I can get that correctly visible/hidden to the appropriate players, I’ll add the third person weapon actor and simply set it up with inverted visibility per client; or at least that’s the plan.

im not sure if this is the issue but remove the server call on begin play and use a switch has authority. since begin play runs on server and client and only the server should be spawning that’ll at least make it clearer since you dont have to worry about ownership

Hey Auran, assuming I set this up the way you meant, I get the following results.

Switch Has Authority replaces the server call at the end of BeginPlay, followed by the same Init Weapons function from earlier:

image_05

And the result is this - server on the left, client on the right. Server’s weapon is spawning, but setting Only Owner See is making it invisible to the server player, and visible to the client, which means somehow the client is ending up as the owner of the server player’s weapon actor (I tested this by disabling the loop that sets Only Owner See, and the server can see his own weapon again but the situation is otherwise unchanged). Client’s weapon isn’t spawning at all:

okay so is something seems wrong further back, are these player pawns and possessed by player controllers? lets sort the ownership problem first

a few other things to test, is the weapon spawning for both but maybe not attaching, it could be at (0,0,0) for instance.

starting throwing print strings everywhere, who are the owners, is spawn being called on both etc

also throw a 1s delay before the function call, im wondering if get owner is being called before ownership is replicated.

So I followed your advice today, messing around with a bunch of print strings and trying to figure out what all was going on.

All the logic is taking place inside the character BP that is owned and possessed by player controllers. Previously I was setting the owner of the weapon to the respective player controllers. Instead, I set the weapon BP owner to be the character BP, and moved the logic setting “Only Owner See” into an OnRepNotify for the EquippedWeapon variable. A combination of these has got me to a point where the visibility is correct for the server and client. Server sees his weapon, client does not.

However, the client’s weapon is still not spawning at all. I checked this with a Get All Actors of Class, looking for BP_WeaponMaster; it is returning only one entry, for the server’s weapon. Still can’t figure out why that’s the case.

I also, after reaching this point, added logic to spawn the third person weapon actor, and setting it to Owner No See in the same way I set up the first person weapon. This also works as intended; client can see the third person weapon only, and server sees only his first person weapon. But again, this is only true for the server’s weapon actors, while the client is spawning nothing at all.

Still, it’s progress and I very much appreciate the assistance. I’ll continue to play around with it. I can’t understand why nothing is being spawned for the client, as far as I can see the server should be running this logic for both character BP’s present in the world, but a Print String right at the beginning of the “Init Weapons” function confirms that it is running only once. I added a big delay as you suggested just to make sure that everything has time to load in and exist, but it hasn’t helped (at least with that issue, I do think it was necessary in getting the other stuff thats now working, to work).

One other strange thing; setting Only Owner See seems to be working only for skeletal mesh components. The weapon magazine is currently a static mesh, while the main body is skeletal. I’m setting the boolean by getting all primitive components, but even getting the magazine mesh directly and setting it’s Only Owner See appears to have no effect. Is this normal behavior? I suppose I can make every weapon-related mesh, attachments, optics and all into skeletal meshes and “solve” that problem, but it seems a bit odd that static meshes behave differently.

ah yes, onlyownersee only works on the playerpawn owner i believe, likely because its replicated to all and controllers arent.

regarding the spawning, clients shouldnt spawn anything but for testing you can try and remove the switch has auth, if that is the problem then id say the weapon isnt replicated when there server spawns it.

with the clip etc, onlyowner should work, im not sure if it matters but check if all components are replicated too

actually on second thought onlyownersee needs to be set on both server/client so just run it on begin play, or better yet just set it permanently in the weapon BP

@Gronklywonk I have a nearly-identical setup to yours where I want each client to only see the 3rd person mesh, while the 1st person mesh is attached to hidden arms. Did you ever solve this problem and if so, could you share the solution? Just like you, this problem has been driving me up a wall