Server spawned actor - not working in GameMode?

I wanted a central place to put actor spawning for my multiplayer game. Unfortunately, Function libraries are unable to spawn actors.
So, I moved the blueprints to GameMode. Worked fine.
Then, I realized I needed to be running with dedicated server checked. Now, the actors no longer spawn.

I realize GameMode isn’t replicated, which is fine. But this seems to only be a dedicated server thing. What should I be using? Am I doing it wrong? The server needs to spawn some items on its own, from saved data.

Thanks!

Let me add…the only way I can think of to handle this instead is to just create a static actor in the scene, which basically just has the functions I need and I’ll call them from a function library or something.

Yes GameMode is only on the server. GameState however is also on the clients and could maybe be used or you could use a separate blueprint to keep things organized.

The server has to spawn all those things that needs to be replicated but you can do that from any blueprint that runs on the server.

What should be triggering the spawn?

I don’t see why you wouldn’t be able to use the GameMode here.

Can you tell us a bit more about your logic please?

If you use GameMode then only the Server can trigger functions on it as the Clients know nothing about it. If you do it right then you should be able to spawn anything you like from the GameMode just like it by default spawns in the selected PlayerPawn at the StartLocation.

I guess I’m a little fuzzy on the “do it right” part. I ended up adding a special actor to the scene, which which other blueprints call to spawn server side objects.

This seems a little odd to me, to have to create an actor just to spawn objects from a dedicated server. Is this really the preferred solution?

You could possibly also just use the level Blueprint if you don’t want to make a separate Blueprint.

You know, I often forget about the level blueprint, thanks. I’ll see about its possibilities.

What should be triggering the spawn?

I don’t see why you wouldn’t be able to use the GameMode here.

Can you tell us a bit more about your logic please?

You better off not using the Level Blueprint most of the time.

Sure!
I save Actor information (type, transform, health, etc) in a SaveGame. The save and load game blueprints were in my own Game Mode class, which derives from Game Mode Base. I’m not sure if deriving from Game Mode Base is a potential problem. Anyway…

At Server launch, I expect it to load the savegame, cycle through the values and spawn the actor given the class, all within my custom Game Mode class.

I noticed before I switched over to dedicated server, I was getting some very odd behavior in the loaded actors. About half would show, but the other half did not. The really weird thing is, when my character stepped on top of one of the missing actors, my character AND the actor suddenly appeared high above the ground, just suspended in midair. If I stepped off of the actor, he was back where he should be, on the ground. Sorry, I know that sounds weird, I swear I was completely sober AT THE TIME.

So, when I switched over to dedicated server, suddenly the actors wouldn’t spawn at all. Not on the server OR clients. Only when I moved the spawn blueprint logic to an actor I placed in the scene did they start showing up.

Regardless…what it boils down to is, what is the preferred way for a dedicated server to spawn objects on its own (like from saved data). I’ve already seen that blueprint functions cannot spawn actors. Just trying to figure out the preferred approach. I personally do not like having to have an actor in the scene that is a poor substitute for a function library, called by other blueprints. It’s clunky.

1 Like

Are you trying to get a reference to the GameMode directly from a Client machine? If so that’s why it’s not working, the GameMode only exists on Server.

The GameState might be the system / class you are looking for as it exists on all machines.

Nothing weird, you’re just doing odd things with the network and Unreal is trying to catch up :wink:

Hmmm Yun-Kin, I’ll make sure I’m not trying to reference GameMode directly from the client, but I don’t think that’s the case. I’ve been aware that GameMode is server only, in fact that’s why I chose to use it.

How do you tell the GameMode what to spawn?

Just wanted to point out, if you are making a multiplayer game, you should extend from GameMode instead of GameModeBase, as GameMode contains additional multiplayer logic built-in that while may or may not be affecting you in this particular issue, will probably be critical for something down the road related to multiplayer.

My GameMode class at startup loads data from the save game, and spawns from there.

I’ll see about deriving it from GameMode instead of GameModeBase, maybe that will do the trick!

I need to see some screenshots of how you create / save / load the save game object and the related logic code.

GameMode is primarily adding MatchState so if you don’t need to know the state of the match it is not necessary. Whatever you do pick though you need to make sure that you don’t mix them.

So if you pick GameMode then you need to use GameState.
If you pick GameModeBase you need to use GameStateBase.

1 Like