UE4/C++: C++er ãUE4åã®ã·ã³ã°ã«ãã³ãä½ãéã«æ°ãã¤ããäº
ãUE4 ã«ã¯ã¬ãã¼ã¸ã³ã¬ã¯ã·ã§ã³ãããããããç¹ã« C++er ã¯æ£ããå®è£ ãéå°ã«æ°ã«æããå¿ è¦ããããã
UE4Editor ãã GUI ã§ãè¨å®ã§ãã GameSingletonClass
, GameInstance
ã使ãå ´åã¯æ°ã«ããå¿
è¦ã¯ç¡ããä»åã¯ãã®ä»çµã¿ã使ããªãå ´åã®è©±ã
UObject
æ´¾çåã®ã·ã³ã°ã«ãã³ã»ãªãã¸ã§ã¯ãã C++ ã®å®è£
å´ã ã㧠NewObject
ãæå³ããªãã¬ãã¼ã¸ã³ã¬ã¯ã·ã§ã³ãè¡ãããªãæ¹æ³:
// static ãªã·ã³ã°ã«ãã³ã®ã¤ã³ã¹ã¿ã³ã¹ãåå¾ããã¡ã³ãã¼é¢æ°ãªã© UMySingletonType* GetInstance() { if ( instance = nullptr ) { instance = NewObject< UMySingletonType >(); check( instance ) // â ãã: UObject ã®åºåºåã® UObjectBaseUtility ã®ã¡ã³ãã¼é¢æ° instance->AddToRoot(); } return instance; }
ãã¾ã«å¿ãããããã¦åååä½ã«å®å¿ãã¦ãã°ããã1å以ä¸çµéãã¦ããã¤ã³ã¹ã¿ã³ã¹ãäºæ ãèµ·ããããã®æãç´æ¥ã¤ã³ã¹ã¿ã³ã¹ãèªèº«ã®ã³ã¼ãã§æ±ã£ã¦ããã°ããã«æ°ã¥ããããã®ã¯ã©ã¹ãä»ãã¦ä¿æãã¦ããã¯ããªãã¸ã§ã¯ããã¯ãã¼ãºãã½ã¼ã¹ã®ãµã¼ããã¼ãã£ã¼è£½ã®ã©ã¤ãã©ãªã¼ã«å¼±åç §ããã¦ããå ´åãªã©åå ã¸è¾¿ãçãã«ã¯æéã¨çµé¨ãå¿ è¦ã«ãªãå°é£ãªãã°ã¨ãªãã
ãªãã UObjectBaseUtility::AddToRoot
ã®å¯¾ã¯ UObjectBaseUtility::RemoveFromRoot
ãUObjectBaseUtility::AddToRoot
㯠UObjectBaseUtility::SetFlags( RF_MarkAsRootSet )
ã¨çãããRF_MarkAsRootSet
㯠EObjectFlags
ã§å®ç¾©ããã enum
å¤ã