[UE4]GameMode, GameInstance, GameState, PlayerState的区别

whats the deferent between gamestate and game instance

https://answers.unrealengine.com/questions/189120/whats-the-deferent-between-gamestate-and-game-inst.html

GameState is replicated extension of GameMode, since GameMode it self is not replicated and exists only on servers memory for security reasons. So GameState let clients access some game data which you would normally place in GameMode, primerly scores and match time, stuff that you usually see on scoreboard. This is only info that client will have and GameMode should have info which only server should know. You can ignore GameState if you creating single player only game.

 

GameInstance is a class that which state persists switching of levels, game mode switches etc. where classes like GameMode or PlayerController are being reset and any data stored in them is deleted and put to defaults again. Any data that you want to keep beyond levels and matches, for example "what player did in specific moment so you can have consequence on other level" should be placed here. This class is mainly helpful for single player games... but it can find uses in multi player too ;] 

The GameInstance is itself not replicated, and exists only on the Server, so its variables won't be replicated either. Your best place for something you'd want replicated from the GameInstance would be the GameState, which is replicated.

 

 

For UI of multiplayer game you should use GameState and PlayerState ofcorse

=================================================

GameInstance官方解释

https://wiki.unrealengine.com/Game_Instance,_Custom_Game_Instance_For_Inter-Level_Persistent_Data_Storage

One of the new UE4 engine features as of 4.4 is the Game Instance class!

This is a globally accessible instanced UObject that can store any data you want to be carried between levels!

Where formally you would have had to write out data to a config file or to binary file, to transfer between levels, now you can use the Game Instance class!

 

 

===========================================

GameMode vs GameState

https://answers.unrealengine.com/questions/122429/gamemode-vs-gamestate.html

They Are Very Different In Multiplayer Game

Game Mode = Only Exists on the server, and controls how players login to the match, and how player units are spawned. You can stop a player from joining a multiplayer game here, or know when a player has left. And again this actor only ever exists on the server.

 

Game State = Ideal for managing all aspects of a replicated world, such as world time, world object positions not owned by a player, AOE damage zones, neutral replicated gameplay elements of any kind.

 

This actor exists for client and server and allows for each client to know stuff about the world.

 

Again a great example is World time where you want the client to know what what the session / turn / current mission time is as propogated to each client from server calculations that are done in Game State class on the server, and replicated to each client using a replicated Time variable.

 

The bulk of actual game-time related stuff in multiplayer game has to be done in Game State if it is anything you want clients to know about locally :)

 

Rama

 

 

===========================================

Where should I create a manager class : in GameMode or GameState?

https://answers.unrealengine.com/questions/43894/a-manager-class-in-gamemode-or-gamestate.html

This is a bit confusing to me. UE alread has these 'manager' classes set up for you. All you have to do is use them.

You are tying to make manager classes to do the following:

Modify Gameplay - This should be done in the GameMode class

Update Scores - This should be done in the GameState class

Player Statistics - This should be done in the PlayerState class

Now all of these classes are replicated automatically. Check this out: Link to GameMode Docs.. .you can see that you set these all up for the engine to manage internally... you just use them.

What you are trying to do is implement a system that already exists.

Look at the Gameplay Framework Docs to get a better understanding of this.

Good 

 

 

===========================================

Gameplay Framework官方文档

https://docs.unrealengine.com/latest/INT/Gameplay/Framework/index.html

 

猜你喜欢

转载自aigo.iteye.com/blog/2268557