Hello,
I made a weapon spawn and it’s working but the problem is when i run on server with 2 charcters one of the character see a kind of weapon and the other see another kind of weapon cause my spawn is random and i want them to see the same spawned weapon
the spawn item function should only be called on the server, and the weapon needs to be replicated,
if you do that the server picks a random weapon and the client just gets the result
It depends on exactly what you want.
If you want to spawn one actor, then whenever you’d do the spawn, make it a custom event and replicate it as run on server. Then when the server spawns the actor, depending on the actors replication settings, each client will see that new actor the server created. You now have 1 actor, that everyone sees.
The second way, is if you want these to spawn locally on just two or something clients (but not all perhaps), is to have a message of some form that comes from the initiating client or possibly server, and then tells the spawning clients the “random” index or class that was chosen so they can all chose the same “random” item.
One example might be to have one character spawn these by sending a message to the server that says to do a random spawn. The server then multicast a message out to the clients. This message includes the randomly picked index or class variable in it that the server would figure out. Now, on the clients, have some condition that determines which clients should or should not go ahead with this spawning of an actor locally, and then for the ones that should they spawn it based off of that index or class value the server had sent.
Thank’s I did fix it but i got another problem and the problem is that it’s spawning sometimes two weapons in one place instead of 1 weapon only
Make sure the spawning event only happens on the server in those cases. Use an “Is Server” node to double check that you are only spawning an actor on the server, and not also spawning them on/from a client.
Checking if you should spawn is always good,
additionally you should try to only run the spawn logic on the server.
As an example let’s say you spawn a weapon every 30 seconds, then the timer for that should only run on the server. Reduces the workload on the client
Hello,
Thank’s For Replying And here is my weapon spawn picture can you tell me exactely what to change or what to do cause i’m completely new
In this case, show where the function is being used, rather than inside of the function itself. Since what we need to see is how you’ve set up replication or server checks.
If you are ok with this being in the regular checks on other clients though, then you could in this function just add at the very start a branch node, with a “Is Server” node plugged into its boolean input. If true, then continue on the shown execution chain, if false, then just do nothing.
Personally I’d place such a check outside of this function before the timer or any other aspects of this even get called though, since there’s no reason for any of that either to be run on clients in this case.
Thank’s Man I really appreciate your help i fixed it because of you thank’s again