Spawning same character with different mesh

I have a working login system where a users is prompted credentials then presented with the character they have created. The characters information is queried from MySQL and works great within the character selection level but it uses a dummy character (not actual player character) and just applies the meshes.

The issue I am running into is spawning that “customized” character in game. The character selection level is opened locally but once the player selects a character they join the server. I am not sure what would be the best way to go about saving the details from the character selection level and applying them when a client joins the server.

You could set it on the game instance and retrieve it in the new level from the client side pretty easily. That is unless you wanted to strictly query a database like MySQL and do it over the server only.

That is sort of what I am doing now. Maybe I should change my approach, but there are 3 different levels 2 different controllers and 2 game modes. Player starts at the login level where they enter their credentials and depending if they were successful they transition to the character selection level. Prior to loading the character selection level an array is saved with all the characters that were queried from DB. When character selection map is load it gets the first index of the character array (if any) and displays that character. Once character is selected they are able to join the server.

Login and character selection levels both use menu controller and menu game mode.
Server is using simple basic debugging map using actual game mode I plan to use.

I tried using Game Instance and kind of got it working as I am able to log into different accounts and the same time and see different characters displayed.

How would you recommend saving those character variables? Should I just have a skeletal mesh variable in GI and have it set on the character during begin play or have any suggestions on how I should go about this?

Doesn’t seem too far away from what I have working… I personally retrieve locally set variables from the game instance on the player controllers since they have total access to any local variable set there. If I wish to persist changes after the game is closed or have certain loadouts, I’ll use save game so I can always instantiate those on the game instance when the player fires up the game.

From there I can replicate any of these game instance variables to any other player from the *player controllers over to the player state and player character and so on… I’m sure this method isn’t cheat proof, but it works. It is a little tricky syncing everything in the appropriate order to replicate and fire, so that is the only major hurdle I think.

I find it easy to communicate those replicated actions and variables(character changes and such) to the player character from the player controllers with RPC’s and Rep Notify functions. That is once they are retrieved from the local player’s game instance via the controller.

I can move between servers and levels and pull all these variables anywhere since they persist until I change them back and forth and any player controller you use can access them as well at any time.

As far as I have tinkered with on skeletal meshes, I was able to just Set Skeletal Mesh on the character blueprint to easily change between already targeted skeletal meshes in-game(not addressing replication). You could expose that variable on spawn and run the Set Skeletal Mesh on event begin play of the character blueprint…

If you have components attached to that character, you may need to show/hide each of them when you make the changes unless all your meshes are very similar and replicate those actions.

You could easily store these mesh variables on the game instance and run your replicated logic from any player controller after post login.

So in the menu if the player selects a character, you could set that variable on the game instance to something like “SkeletalMeshToSpawn” and then when you travel into the level, the new player controller or the same one will restart and you can get that non replicated game instance variable and set it on the appropriate blueprint, but at this point you would need to replicate it.

I feel like you can use any number of player controllers, levels and game modes without causing any issues or changing anything. I find personally the only way to keep all those in sync without any hiccups is using a single Game State across the whole game. I use the level blueprint to tell the game state where it is and it will run anything anywhere accordingly. I do know that no matter what, unless the game is switched off, I can always find stored variables on the game instance no matter where the player is.

There are other ways, but people rarely talk about them apart from using a database, which is probably a more secure, but proportionally difficult way lol.

I have been trying to work on this during my free time, but I still cannot come up with a solution. Characters information is stored in Game Instance and that is working as client is presented with their own characters. I plan on switching to dedicated servers but just using listen for dev. As it stands right now first player to click connected becomes the listen server and following players join that session. When players join they are getting the server’s information store in GI. I have changed the variables so that they should be replicated but still struggling.

Login Widget

Game Instance

Menu Widget

Setting Character Info in Menu Widget

Player Controller

Game Mode

Well I was able to get it working. Not sure if it is the best way to go about it, but it is working lol. Just have one question and hopefully someone could answer me. In my Character blueprint I have to set the appearance twice. Once locally and once on server. I thought since the character is replicated that just setting the mesh on the server would work.

Player Controller

Player


1 Like

Sorry for the late response. I have a relatively similar setup on the player controller that works well. I’m glad you got it working. I too had to set information on both the client and server as well, but that is on a dedicated server so I’m not too sure.