Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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 Main Code

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

But as you can see here, it changes the character reference to an unknown one when passing to the server Print outputs showing the changed ref

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

Product Version: UE 4.10
more ▼

asked Jan 23 '16 at 06:26 PM in Blueprint Scripting

avatar image

18 6 9 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Jan 23 '16 at 08:39 PM

avatar image

1.2k 24 13 29

avatar image Timbo59 Jan 23 '16 at 10:05 PM

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

avatar image Bariudol Jan 23 '16 at 11:06 PM

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.

avatar image Timbo59 Jan 24 '16 at 05:09 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question