Spawn Actor on server

Hello,
I have a blueprint that should spawn an actor. The actor should be spawned from the server. Then the material of the actor should be changed.

The actor spawned but the material is not changed.

T


his is The Graph Called From Client and it Fires and spawn the actor.

The material change doesnt work, the variable is on the Construktion script of the spawned actor

Hope you can help me

Hey there @Mathrim! This is a bit of an odd one, as the construction script should be able to apply to server and client alike as long as the actor spawned is replicated and relevant. I had first thought this was a replication issue, then I recreated this and I couldn’t hit your issue at first until I realized if the construction script is active, setting the material after doesn’t work even on the server. Even with a Delay I couldn’t change the material unless I disabled the material change in the construction script.

Going to toy with this for a bit to see what I’m missing and get back to you.

I have tried to Set the material without Constuction Script but it also dont work

But this Graph on the spawned Actor BP works fine

I delete the “event begin play” and call the Event from SpawnerBP the event but it dont fire

Well you are calling a server function, to spawn an actor, that is replicated, so it spawns on the clients as well. But then you are setting a material, which by the way should not work like that, because the construction script is effectively run when the actor is spawned, so your material variable at that point still doesn’t have your selected value.
You could make your material variable RepNotify, and then in the OnRep function of it set the material. That way you can set it on the server and it will work as you expect it to work, and then when the variable gets replicated to the clients it will also apply the material change there

1 Like

Ok it works, and now i want to destroy my actor but it dint work

I have read there is some Problem with the spawning client copy or server but i didnt realy understand

In general only the owner can destroy actors, so in multiplayer scenarios if an actor was spawned by the server, owned by the server, that means that the server has to destroy it. Since the actor is replicated, it will get destroyed on all clients as well

2 Likes

Ok i change the “Multicast” to “run on server” and it works

But when did i use the multicast?

Multicast is for when you want the server to call a function on all clients. So the usual flow could look something like Client calls Run On Server function, and then the server does the logic and runs Multicast function to update the clients if needed. If you try to call a Multicast function from a client with no authority, then the multicast function is absorbed and is only run locally, which will cause issues, because the client will change its state to something potentially different than that of the server

Another thing, for the majority of the time, most gameplay logic should run only on the server. So I’m not sure what you’re doing right now, but it’s not really a sign of a well built architecture to have to call Destroy on a Server owned actor from a Client. Ideally, the logic that requires the Actor to be destroyed should be on the Server, and then the server just destroys its owned actor.

Usually destroying an actor on a client is only used for some spawned cosmetic actors maybe, or actors that are completely local to the client

1 Like