UE4-GameInstance

GameInstance是什么

  • (UE4官方)是一个正在运行的游戏的高级别的管理对象,在游戏创建时生成,游戏实例关闭时销毁,一个游戏中可以有多个GameInstance;
  • 在游戏中切换关卡,GameInstance不会销毁(切换关卡时可用GameInstance携带信息);

GameInstance作用

  • “Init”与“ShutDown”:引擎初始化与关闭时执行的逻辑;

UE4-GameInstance

UE4-GameInstance

  • “NetWorkError”与“TravelError”:网络和跨关卡时的错误;

UE4-GameInstance

  • 与LocalPlayer相关:

UE4-GameInstance

  • 为游戏保存全局数据:比如上一个关卡的信息需要在下一个关卡使用时;只是临时数据,游戏结束则消失;(持久保存数据需要用SaveGame)
  • UI界面的切换:UE4中的UI比较独特,是通过独立的Widget来产生,使用时需要Create此Widget然后show出来。复杂的并且重用的UI界面切换逻辑可以在此实现,因为GameInstance在各个类中都可以获得,方便各个地方调用;
  • Network、Session相关的事务;管理Session;

UE4-GameInstance

  • 自定义的需要全局使用的逻辑:比如TCP、UDP通信,因为绑定本机IP和端口、并且发送和接受的方法实际上只定义一次,因为跨关卡的特殊性,不可能在每个level中使用一个Actor每次都设置一次,所以应该写在GameInstance中;

GameInstance的创建与使用

1、选择GameInstance父类创建GameInstance蓝图:

UE4-GameInstance

2、在Project Setting中的Maps&Modes指定GameInstance

UE4-GameInstance

 

相关文章:

  • 2021-07-08
  • 2021-06-29
  • 2021-12-07
  • 2022-12-23
  • 2021-07-28
  • 2021-07-09
  • 2021-08-07
  • 2021-05-29
猜你喜欢
  • 2022-01-21
  • 2021-06-28
  • 2021-12-04
  • 2021-10-19
  • 2022-01-10
  • 2021-04-19
相关资源
相似解决方案