UE4/C++: NewObject ã§çæãããªãã¸ã§ã¯ãã® Outer ãå¤æ´ãããå ´åã®ã¡ã¢
âããããã®ãå± ãã¨ããã
// UObject æ´¾çã ãã·ã³ã°ã«ãã³ãã¡ã¯ããªã¼ã§çæããããªãã¸ã§ã¯ãããã£ãã¨ãã UA* UA::GetInstance() { if ( ! my_static_instance ) my_static_instance = NewObject< UA >(); return my_static_instance; }
ãã®ãããªãã¡ã¯ããªã¼ã§å¾ãããä»çµã¿ã® UA
ã®ãªãã¸ã§ã¯ã㯠Outer
ãæããªããã GetWorld()
ãã¦ã nullptr
ã帰ããªã©ä¸ä¾¿ãªäºããããå¹¾ã¤ãç¡çããæ°å³ãªæ¹æ³ã¯æãã¤ããã®ã®ã Outer
ãå¤ããè¨å®ã§ãã¦ãã¾ãã°ä½ãã¨è§£æ±ºããããã®æ©ã¿äºãçããé㯠UObject::Rename
ãæãç°¡åãªè§£æ±ºæ¹æ³ã«ãªãäºãããã
// UGameInstance ãªã© World ã«çµä»ããããä½ããã void UMyGameInstance::Something() { auto a = UA::GetInstance(); a.Rename( nullptr, this ); }
ããããã¨ã以é㯠UA
ã®ãªãã¸ã§ã¯ãå
é¨ãããããããã« NewObject<T>( this )
ã§çæãããªãã¸ã§ã¯ã㯠Outer
ã®çµã«ãã GetWorld()
ãæå¾
åä½ããããã«ãªãããã¡ããããã£ã¨ç°¡åãªç¨éã§åç´ã« Outer
ãå¤æ´ãããå ´åã UObject::Rename
ã§åæ§ã« Outer
ãå¤æ´ã§ããã
UObject::Rename
ã¯é¢æ°åããã¯ãªãã¸ã§ã¯ãã®ååãå¤æ´ããã ãã«è¦ããããã·ã°ããã£ã¼ãè¦ãã°ç¬¬2å¼æ°ã« UObject * NewOuter
ã¨ãããå®è£
ã§ã¯ç¬¬1å¼æ°ã« NULL
ãããã©ã«ãã§ä¸ãããã¦ãããçç¥ãã¦å¼ã¶æå³ããããã¯ãã¦ãããååãå¤æ´ããå¿
è¦ã®ç¡ãå ´åã«ã¯ nullptr
ãä¸ããã°è¯ãäºãæ¨éã§ãããï¼å®éã«ç¬¬1å¼æ°ã¯ nullptr
ã§ãã®ããã«åä½ãããããï¼
// Runtime/CoreUObject/Public/UObject/Object.h /** Rename this object to a unique name.*/ virtual bool Rename( const TCHAR* NewName=NULL, UObject* NewOuter=NULL, ERenameFlags Flags=REN_None );
ä¾ã«ãã£ã¦äºå®ä¸ã¢ã³ããã¥ã¡ã³ããªã®ã§ä½¿ãå ´åã¯ã½ã¼ã¹ãèªãã æ¹ãè¯ãã
// Runtime/CoreUObject/Private/UObject/Obj.cpp bool UObject::Rename( const TCHAR* InName, UObject* NewOuter, ERenameFlags Flags )
ERenameFlags
㯠RF_ClassDefaultObject
, REN_ForceGlobalUnique
, REN_Test
, REN_ForceNoResetLoaders
, REN_NonTransactional
, REN_DoNotDirty
, RF_Public
ãªã©æå®ããã¨æå³ãããããã ããããããã Outer
ãè¨å®ããããã¯æ¿ãæ¿ãããã ãã®å ´åã«ã¯å®å¼æ°ã¯çç¥ã㦠REN_None
ãä¸ããã°è¯ããå®è£
詳細çã«ã¯ LowLevelRename
㨠PostRename
ãå¼ãã§ããã®ã§æãã®ã»ãè¤éãªäºããã¦ããã