heapcleaner

Untitled

Mar 14th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. /// .h
  2.  
  3. UCLASS()
  4. class UMyGameInstance : public UGameInstance
  5. {
  6.     GENERATED_BODY()
  7.     static TWeakObjectPtr<UMyGameInstance> Instance;
  8. public:
  9.     static UMyGameInstance* Get() { return Instance.Get(); }
  10.  
  11.     UFUNCTION(BlueprintPure, Category="Game")
  12.     static UMyGameInstance* GetMyGameInstance() { return Get(); }
  13.  
  14.     virtual void Init() override;
  15.     virtual void Shutdown() override;
  16. private:
  17. };
  18.  
  19. /// .cpp
  20.  
  21. TWeakObjectPtr<UMyGameInstance> UMyGameInstance::Instance;
  22.  
  23. void UMyGameInstance::Init()
  24. {
  25.     Instance = this;
  26.     Super::Init();
  27. }
  28.  
  29. void UMyGameInstance::Shutdown()
  30. {
  31.     Super::Shutdown();
  32.     Instance.Reset();
  33. }
Advertisement
Add Comment
Please, Sign In to add comment