Download

2 codes work in Editor, but not in game!

Hello,

I have the made 2 lines of codes, which works perfectly in the ARK Dev Kit, but when testing it in game it didn’t work. Both of the codes are placed in the PlayerController.

First code:
2458089b037c3e6cf63d958adf1a6680d6e3c29e.jpeg

This is a function which spawns in a dino, which you can play, it is triggered by a button in a widget . This function is Excecuted on server and Reliable. In the editor I tested it on Dedicated and Non-Dedicated with 2 players. The Client and Server were both able to spawn a dino.

People who play the mod tried it on a Non-Dedicated server. Only the Server was able to spawn the dino, the Client couldn’t do anything. How do I get it to work in game? Will it work on a Dedicated server, or will it be the same as on Non-Dedicated?

Second code:
31fd8bd97a9a84f8ad41671575aed95572af75f5.jpeg

This function is called when clicking RMB. The function is Excecuted on server and Reliable. It simply tames all Direwolves in a range when playing as a Direwolf. (You howl and wolves will join your pack). First it checks if the Direwolves aren’t tamed by any other player yet.

I tested it in the Ark Dev Kit by placing 2 Direwolves in the TestMap and pressing RMB, this worked and the Direwolves were tamed. Sometimes it did’t work at the exact moment, but after pressing RMB 2/3 times. I thought this was caused by all the loops.

In game I tested it, but the wolves were not tamed, instead the attacked me like usual. I also could not see the message at the end of the code because that part of my HUD has disapeared, but that another thread/problem. So I am not sure if the last piece of code is excecuted.

I think the problem is caused by the last piece of the code, but I am not sure. What is wrong with the code?

Thanks in advance for answering! If you found some other improvements in the code, please let me know.

I think you are just missing the “switch has authority” nodes in you “run on server” events. I initially thought if you call a “run on server” event from the client it will only run on the server by default but it seems like you need the switch especially when calling from widgets: Run on Server / Has Authority - UE4 AnswerHub

I would try adding those first. They might not be the whole problem but so far that is the only thing i can think of that could be wrong here.

About the “Server Client Notification”: I noticed that despite the description saying: “run on owning client(if server)” you will need to call this function through its own “run on owning client” custom event. Calling it directly on the server will work in the editor but not ingame.

So I need to place a ‘Switch Has Authority’ node in the widget’s blueprint and connect the Authority output to the rest to the rest of the code? Then I need to change the Replication setting of the function to ‘Multicast’?

No you just need to add “switch has authority” at the beginning of your “run on server” events with just the “authority” execution connected like so:

Thanks! I will try that!

Do you know what is wrong with second piece of code?

I think your probably going to want to re-evaluate where you have your “Client Set HUD” call. It says to replicate on owning client (if server), however where you have it, it is attempting to run on the client’s end. You could also change it so that this event isn’t set up to replicate and it’ll spawn the HUD immediately after sending the RPC to the server.

Unfortunately, I can’t read the second picture because the font is too small for me. :slight_smile:

Yes, if you could zoom in the screenshots one more step it would be much easier to read :smiley: On the first screenshot i noticed two other things:

  1. There is a connection that seems to go a weird way not sure if im not seeing this correct but it looks like one target of “Clear Rider” is connected to “as Dino Character PAD” way later in the execution. Not sure if this would just be empty and ignored but it looks like its just a little mistake.
  2. I would be interested to see where the “Player” variable that gets passed to the “Spawn Dino” event comes from.
    Tried to mark those two thing in here(sorry for my bad paint skills):

The ‘Client Set HUD’ is a node in the editor, not a custom function made by me, so I can’t change it.

The first part of the second code:

The second part of the second code:

I will add the Switch Has Authority node in this code too.

  1. Thanks it was indeed a strange connection. I was somehow connected twice, also with the ControlledDino var, but I remove the connection.
  2. It is connected with the ‘Get Controlled Pawn’ node.

Thanks for taking a look at it!

Does anyone know what is wrong with the second code?