Hello,
Looking for what is wrong for a full day.
Have a line trace that when hit something update a variable LookAt (Actor Object)
Then I do an update of the variable using a custom event that run RPCs to update on all.
No matter what Player (0) look at is update for all LookAt variables on the Player (1), not only to its local player (0) but also to his own LookAt.
As you can see on the second picture client is looking to Ammo but the variable Lookat on the 2 server players and 2 client players have bread on it, I cannot figure where else to look.
If I open the players on the debug window all 4 have Bread on Lookat variable.
I try using replication on or not on the variable same happens.
I am probably missing something very simple.
Thank you for any help.
Have a line trace that when hit something update a variable LookAt (Actor Object)
Then I do an update of the variable using a custom event that run RPCs to update on all.
On your look at client, you set the variable then call server to multicast on all client. This includes the original client who’s already setting the variable. This may cause inaccurate variable which is getting set on client and server both time.
And if you are doing the RPC in tick events, remember there are network issues to consider. The order of your RPC might not be correct with package lost. You can simulate that in PIE with the following.
you want a RepNotify not a MultiCast for things like this,
otherwise as Kiray said it could it could just be lag
Hello Kiray,
Thank you, looks like works, I just want to understand this on the debug windows there are 2 Trey0 and 2 Trey1.
The top 2 (Trey1 and Trey0) got a bread and the Bottom ones got ammo.
I was thinking both Trey0 on the list should have the bread and both Trey1 have the ammo.
Also I read every where that the way to do this is using the call to the server and then the server call all, but looks like for variables is just do a call all.
I know about the lag, happy got something working, will look into the RepNotify that Auran13 mention.
Thank you
there are 2 because they both exist on both server and client
the correct way is Server RPC to RepNotify
Replicated/RepNotify is to keep a variable up to date
Multicast is for one time events, like play a sound
Thank you Auran13
Playing with RepNotify now, is confusing when you have an event that does not happen much, like get the item and put in the hand, need to spawn the item on the hand show to both players, then are variables there that may need to repnotify (like what is on hand) inside the same event. Just confusing for now, I will get there.
Thank you.
Hello,
I am back.
I made a video to show what I am getting, maybe someone can give me a help, I try a bunch of RPCs combinations, replications combinations… I just select one to not make this very confusing.
The video is with the LookAt and LookAtLocation set to replication and the code is below is very simple, if I press 2 a copy of the object I am looking is spawn on the location I am looking.
One the video
1-Server looks to a bread and press 2, server gets a extra bread but client gets 2 extra breads.
2-Client goes and look to a box and press 2, for the client 2 extra breads are spawn on the location where server is looking and 1 appear for the server.
3-Now get weird, server then looks to the sky, nothing to see, client press 2 on the box and a copy of the box appear on the client but not on the server.
4-Server goes back to the bread and look to it, client again press 2 and now 2 extra bread appear where server is looking for the client and 1 for the server.
Looks like the server variables are like more important than the the client one…
If I can get any help I appreciate. Thank you.
Again dont multicast, you only spawn things on server unless its something non gameplay related like a visual effect.
Also check the actor you are spawning is set to replicate
finally replication only works server/to client not client to server so for your variables like LookAtActor/Location need to either be set on server or passed through to the ServerRPC
Thank you Auran13,
Now that makes sense for me, I was thinking replicating the LootAt would update it on the server and the server would send to others.
The class is set to replicate.
Now how my client can get the object he is looking but have updated value only on the server on replication and then server sends it to others?
Is there other parameter? I see bellow the option to replicate the variable there is a drop down with Initial Only, Owner Only… is one of them that will make that be updated on the server and them on the clients.
The set of the Look at is on the line trace, that is the only place is updated, do I need to set something else to make sure the server has the control of this variable?
I understood but I am confuse.
Thank you very much for the help.
to update a server variable, you can either
Run the LineTrace again on the server however this will introduce a lag delay
OR
do a RunOnServerRPC and then add input nodes to that event, off that event set the variable with Rep/RepNotify however this can be vulnerable to client cheating
Hello Again,
I was working on somethig that I think is your second option and worked.
Is that what you mean with your second option? Code below.
Now LookAt and LookAtLocation are not replicating.
On your first option using replication looks like would be much more natural (no problem with the lag, I just want to understand now), how would I do the server run the line trace? Put a has authority just after the tick event, or is something else?
Thank you very much.
your event there is fine you just forgot to set the new variables to replicated, you can always tell because it’ll have the double white dots in the top right corner
you dont need the SwitchHasAuth because the ServerRPC will always have authority
Wow, unbelievable.
I got is all now, I think.
Videos on youtube make things much more complicated than they are, I just did 1 call to server and all works also.
I also understood the replication, I made all work.
Thank you so much, now this is clear for me.
Thank you.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.