Attach to Component result in different Locations on Server and Client

Hi folks.

I get a weird behavior when I attach weapon actors for my multiplayer clients.
I’m using the first person template and did some blueprinting to wait until enough players are connected. Then the server spawns the player characters and let them be possessed by the clients’ player controller. So far, so good.

Now on the “on possessed” node in the character blueprint I let the server spawn the weapon for that character and attach it to the projectile-sphere (a collision sphere attached to the character, like in the first person template).
But after attaching them, they result in different locations on the server and on the client. On the server, the location is fine, but on the client, all weapons are attached with a strange offset.

I’ve tested with component replication but nothing seems to work properly. Any idea what I’ve done wrong? (The blue arrow in the pictures represent the position of the weapon actor.)

are you sure, its not the player character that is spawned incorrectly?

Maybe. But what could be the problem when spawning the character? The server spawns them at a location of a player start with a scale of 1. Also the projectile sphere is visible at the correct place (Server and Client) and if I don’t attach the weapon, it’s at the correct place too. So I guess it’s really something with the attaching thats wrong…

Does your weapon have any collision presets that can interfere? that happens a lot. because if it has, this gives try to adjust location but always spawn stuff to happen. just throwing it out there.

Ok, thanks for your hint. I’ll check that out. But I guess thats not the problem. My weapon actors have just a scene component and some blueprint functions. no meshs or something that could collide (in my opinion). I’m gone try to set collision to “no collision” on both my weapons and the weapon mesh in my character BP.

Tested with different settings now but nothing seems to work. Spawn rule is “Always spawn, ignore collisions”. Also tested with “Don’t spawn” but then it spawns it anyways, so I guess it’s nothing with the collisions, thats wrong. I also noticed, if I just spawn the weapon actor, it spawns at the correct place (server and client) the “attach to” node makes things strange then. If I set the location rule to “keep world” instead of “snap to target”, it keeps moving the arrow to a wrong location. This also happens if I set all the collisions to no collision.

Well, if I put a delay of about 0.6 seconds between spawning the weapon actor and attach it to the component, it works. Probably it has something to do with the characters “use pawn control rotation” but I guess thats another topic.

After working on this for hours and realizing it had something to do with some replication thing I don’t understand, this was my fix. Note that all of the object’s components are replicated(including itself), and these nodes are executed on server only. I guess the server only tells the client about it if there’s a change for some reason, so I just added an instant change.

http://i.imgur.com/rc16k2O.png

After long time of ignoring the “issue” I fixed it as well. There was definitely something wrong with the replication. I guess I solved it with RepNotifys from the Weapon/Equipment reference variable. I don’t need a delay anymore and everything seams to work fine. I’ll post my solution (blueprint) as soon as I get a little time. Simply said: Server spawns weapon an sets weapon reference variable which is a repnotify. In the notify function I just attached the weapon like normal. Meybe I also didn’t understand the whole replication stuff at first

Even though this post is old, I am having a very similar issue that I cannot find more information on. Mind sharing your solution?

Like mentioned above: I have a reference to the weapon as a variable with repnotify (its ether not replicated, replicated or repnotify) if you choose repnotify, UE automatically creates a function called “VariablesName”_RepNotify or something like that. this function gets called on server and clients, if (usualy the server) changes it.the variable itself is also replicated. you will call the attache to component in the function and everything should work fine. Hope that helps

I still don’t understand why you had to go through all of this. Ue4 documentation states that any replicated actor that receives an attachment will automatically replicate the attachment. For example I have 2 replicated characters and a replicated actor if I interact with the replicated actor and set owner to the client and attach that component or actor to a slot on the replicated character the attachment should replicate. The location and transform data should be seen by other clients as soon as the replicated character becomes relevant

This is my solution:
I run this macro before each “AttachToComponent” (server)

The locations of client and server objects typically always differ. If you attach something to another component using Keep World Transform, the location it attaches to may be completely different on server compared to client, depending on when it was called. So yes, your solution of putting it in the exact location before attachment works. But even better is to use sockets when possible. That way you are attaching to the socket location, and not whatever the world location might be is when the call is received.

I love you!!!