Hello, there are actors on our level that are only ever used by the server. Currently I’m considering deleting them in the constructor if Role != ROLE_Authority. Another alternative would be to begin all the classes’ functions with if(Role == ROLE_Authority) to ensure only the server uses them. However, ideally the actors should never even spawn for the client. Is it possible to make actors placed on the level only spawn for the server? And if not, what would be the best alternative to handle this situation?
Update: I just found that AActor has a variable bNetLoadOnClient, is this what I should be using?
I had this same question a while back, and we implemented the feature ourselves.
Added bLoadOnClient and bLoadOnserver flags to AActor, and modified NeedsLoadForClient() NeedsLoadForServer(). Client only actors are also a really common use case, to have visual fluff on clients that the server should not need to worry about.
I didn’t implement it, but I know there was trickiness with PIE because of the way it clones the world. I hope the engine supports this feature natively some day, would be useful for most multiplayer focused games.
Just a quick note that checking against Role isn’t enough to check client vs server. Non-replicated actors will have ROLE_Authority on both server and client sides, so the NetMode check is what works better here. Besides that, the role is assigned way after the constructor is called, so it’s too early to query it there.
Other than that - the previous comment is to the point
Yes, bNetLoadOnClient is what you probably want. The client will destroy these shortly after loading. We use this for AGameMode for example, so that client won’t load it (it’s a server only actor).
Let me know if that doesn’t work, or isn’t what you need!