ue4 bp singleton

.h

 UCLASS(Blueprintable)
 class USingletonBP: public UObject
 {
     GENERATED_UCLASS_BODY()
 
     /**
     * Singleton access 
     */
     static USingletonBP* Get();
 };

.cpp

USingletonBP* USingletonBP::Get()
 {
     static USingletonBP* Singleton;
     if (!Singleton || !IsValid(Singleton))
     {
         UClass *SingletonClass = LoadClass<UObject>(NULL, TEXT("/Script/ModuleName.SingletonBP"), NULL, LOAD_None, NULL);
         Singleton = (USingletonBP*) ConstructObject<UObject>(SingletonClass);
     }
 
     return Singleton;
 }


原文地址:https://www.cnblogs.com/nafio/p/9137064.html