Passing references to Run On Server events change them?

So the basic gist of this one is that when I pass a self character reference to an event that is replicated to the server, it will change the reference. I’m trying to pass the client which initiated the trace event, so I can use that later down the code to add items to that particular client, but as you can see from some screenshots I will post, it changes the clients reference.

Here is the code for the trace call

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

And here is a debug print that I made to show the clients character and controller ref

http://i.imgur.com/Qcqpv5k.jpg

But as you can see here, it changes the character reference to an unknown one when passing to the server

http://i.imgur.com/oelmIcS.jpg

Now I could just be doing something really dumb here, but I’ve been struggling with this for a while now.

Some things to note;

When I change the event type to multicast or run on client, it passes the correct reference, but causes problems down the road in areas like cheat prevention, as the item can only spawn client side.

When the server runs the interact code, it passes all the correct references.

I really have no clue what to do. I tried promoting the self value to a replicated variable, and then passing it. But that did not work either. And I can’t make it client side as I don’t want people to be able to spawn in items or pickup items that aren’t really there.

Any help is appreciated

The problem you are having is with replication. Display name should be a replicated variable that is set server side and then assigned to the client. Thats why it works with multicast and when the server calls the function. If you want any variable to be shared with the server it should be set server side and then replicated, such as this case.

I don’t know how you’ve set the display name but in blueprints it should go something like this:

  • Mark the DisplayName Variable as Replicated.
  • Set display name is called on the player controller (it should be a custom function).
  • Checks if its the server (switch has authority)
  • If it is the server, sets the variable.
  • if its not the server it calls a function that runs on server and calls the set display name function.
  • As DisplayName is a replicated variable it will be assigned to the client automatically.

While your DisplayName variable is set on the client, when you pass it to the server you are actually telling the server to check on that copy of DisplayName in the server, wich is null, as it has never been set on server.

I’m not quite sure I understand. My problem is that the character reference I pass is changing, it has nothing to do with displaynames. I tried making a “Controlled Character Ref” in the controller which is replicated, but it had the same output

Oh, I completly missread your post. Still, I can’t figure out what you are actually trying to do:

If you want to add items to a characters inventory of some sort, you should do it on server, and then replicate the item into the clients inventory (by making the inventory replicated; that way, every time you modifiy it on server it will instantly copy to the clients).

The same goes with traces. The trace should be called from the Server copy of your character and it should use its own reference and not the clients one.

When you pass the clients reference to the server you are actually telling the server to use its own copy of that character and not the one on the clients side. Thats the way of doing it and the best way to avoid cheating.

I don’t know exactly what you are trying to do, but this is how i would go about it:

  • Input Interact

  • Switch has authority

  • On True: Do the trace, pass a reference of self

  • On False: Call event “Server Interact” (runs on server, reliable), does the trace with a reference of self (server copy of the character).

  • Add the item to the server copy of the character-

  • As inventory is replicated it copies to the clients.

Also, I would recomend you to this from your character controller and not the character itself. And passing a reference of the character for the trace.

What you are observing is not the reference changing but the server using its own copy of the actor, as it should.

If this does not answer your question, please elaborate more on what you are trying to achieve. I’m sorry if its not helping, hope it does. Cheers.

Actually that was quite informative, I think I might just re-design my entire inventory system, as I made it work for singleplayer, then tried to convert it to multiplayer. Which is just causing so many problems. I appreciate the help