Spawn actor on server problem

When spawning an actor on begin play event, on a client, it spawns 2 instead of 1. Works fine on server.

  1. Creat “run on server” event >> spawn actor from class .

  2. Set “Run dedicated server” option (for playing).

  3. Use the spawning function in the Begin play event from player controller for example.

You will have 2 actors instead of one.

It will only spawn one if instead of “begin play event” i use the spawn event from lets say Press F key.

Hello D2liriuM,

I was unable to reproduce this issue on our end. I have a few questions for you that will help narrow down what issue it is that you are experiencing.

Quick questions:

  1. Can you reproduce this issue on our end?
  2. If so, could you provide a detailed list of steps including any steps that may have been missed in order to reproduce this issue on our end?
  3. Could you provide screen shots of any blueprints that may be involved?

Sadly i could not reproduce this in a clean project.

Here you have some screenshots, just ask for any screenshot you need.
link text

Thank you for the additional information. Would it be possible for you to provide the project that is having the issue so that I could take a closer look? Also, could you elaborate further on the issue that you are having?

I am trying to reduce the project size so i can to upload it. How can i send you a private msg with the link when i finish it?.

edit: I sent you a private msg to the forums, with the link to my project so you can test the bug.

Edit 2: The download speed of the hosting page i used sucks but the project is only 16mb size. Sorry for that :frowning:

Hello D2liriuM,

After looking through your project, it appears that this is working as intended. I noticed that you are using a set of custom events that are set to “Run On Server”. This means that when the Server calls these custom events on begin play and when the client calls these events on begin play that they will run on the server. The reason that you are seeing double is because the events are being called twice (once for the server and once for the client). If you would like this to only run when the server begins play you can use a switch has authority node. I have provided an example below. I hope that this information helps.

Switch has authority example:

In this example I have added the switch has authority node to your blueprints so that the custom events are only called by the server on begin play.

Make it a great day

If i do the exact same thing that i did in the project i sent you in a clean third person project i will only get 1 actor spawned instead of 2. Why?

Edit: Also, if in the project i sent you, you remove that spawn 0, spawn 1 etc from “event begin play” and instead you call them from a key event “Press F key” for example. You will only get 1 actor instead of 2. Why?

Images

Why is different if i use it on begin play or if i use it on other event?.

Thank you for your time.

This has to do with how each of those events are triggered. Event begin play is called automatically as the actor loads into the level. Where as the ‘F’ key is only called when the player does so manually. This means that begin play will fire both for the client’s copy of the actor and the server’s copy of the actor (once each). However, if you press the ‘F’ while you are possessing the actor, you will only do so for the current actor you are in control of(meaning the client because you are running a dedicated server). I have provided documentation below. Please be sure to look over this information for any other questions you may have.

Link: Networking and Multiplayer in Unreal Engine | Unreal Engine 5.1 Documentation

Make it a great day