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.
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.
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 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.
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.
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.