Different Actor location for server and client after spawn

Hi, I am stomped …

I try to spawn and attach weapons on begin play. I have all possible replication settings in details set up (all components are set tu replicate, replicate movement is also on etc.)

  1. In begin play I call custom event InitialSetup (it’s run on server and set to reliable)
  2. In InitialSetup I spawn actor from class then attach it to component
  • collision when spawning is set to always spawn, mesh world tranform is set as spawn tranform
  • attach to component location and rotation is snap to target, scale is keep relative and weld is disabled

After that In my server everything is displayed correctly but client is not.

EDIT1:

I have added HasAuthority check (by printing I can see that It get’s called only on server) but the issue with spawn still exists.

Can you show code where you spawn the weapon?
Do you spawn the weapon on server only? (HasAuthority node before spawn?)

I can post it tomorrow morning (GMT time) - but I am not checking authority. Just calling event with replication set to run on server - isn’t it doing that automatically? (At least I haven’t seen this in blueprint replication wiki)

Well if you spawn a replicated actor with movement replication, that actor should be spawned on server only and engine does replication automatically…

Begin Play called on both Server and Clients, so if you spawn actor there that means you spawn 1 actor on server, 1-1 on clients.
Engine does not replicate anything from clients to server, only from server to client :slight_smile:

technically if you spawn anything on client his position can be invalid since not updated from server (imagine like a standalone actor which exist only on that client)

Oh that makes sense - I am gonna test that tomorrow :slight_smile:

I have updated question with BP code. I have added check but that still doesnt work (Still client has incorrect position). I have also added print and it is called only on server.

Ok, ive checked the code…
Well weird it seems fine. BP_Bow is also replicated and replicates movement right?

Okay, BP_Bow is replicated and replicates movement right?
Hand Mesh is the whole “pig”? or the sword? (Because seems to me sword is also on wrong location)
Hand Mesh replicated and replicates movement too?

So far code is configured properly. (btw you dont need server event if you spawn things on server, but its okay… event would be called anyway :slight_smile: )

Both BP_Bow and BP_Sword replicates and replicate movement (just double checked). Hand Mesh is an invisible mesh (at lest invisible for now) thats ‘floating’ hand near pig (it’s attached to first person camera). I cannot see option to replicate movement on skeletal mesh.

weird… try attach your hand mash to the root instead of your first person camera… (dunno if it make sense, but maybe camera location is different)

Skeletalmesh component has some optimization methods too like when to update (if visible or always) and update on server… give it a try…

Did not work … to be honest I have no idea what should I do. Some world/project settings maybe?

I have tried it and it didn’t work. I am running out of ideas … maybe some project or world settings?

idk, im out of ideas too…
code should be fine, but seems your hand mesh also not in correct place… and i assume its not runtime spawned mesh… should be some small things we missed maybe…
nah no project / world settings modify this i think…
simply hand mesh should be visible all the time (if you added as static mesh component) at correct location

Are you replicating this object?

If yes then can you make ss of replication?

266270-replicates.jpg

these are BP_Sword replication settings (crossbow has the same). All other components has components replicates. After it’s spawned they move ok (so movement replication works) just location is wrong.

When added delay client sees his items correctly but character controlled by server has it in wrong place.

I added delay and it seemed to work …sort of. Client sees his spawn now correct but server’s incorrect … mayby it needs time to calculate location?

yeah beginplay can happen before replication happens…
but since you try to attach on server and replicate movement down should be not issue…

in theory you spawn the bow attach it on server side and you let engine replicates down his position…

i suggest one thing…
make a replicated Bow reference variable for now with repnotify and set as replicate for everyone… after spawn set the bow reference and wait for repnotify

if repnotify triggered (that means all client got the bow) try attach it to the handmesh on clients with snap…
im not home yet, but i would do a test project to test your problem :slight_smile:

That’s great idea to test - I am gonna try that later since I have to go out now ■■■ well.

I have made it so I create actor on server then set repnotif and in it’s function I attach it. It still didnt work but I found this question above - and with small delay before set repnotify it works

EDIT: at least it works perfectly on button input … in begin play client still has issues with seeing server item (but his own item looks ok)

EDIT2: Expanding delay seems to fix it … but I still don’t understand the necessity of this delay.

I was having the exact same issue and found the solution here:
https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/1458882-different-location-of-actor-at-server-and-client

Turns out the mesh must be set as the root component of the Actor BP. I had it attached to the scene.