To understand the difference between these functions, you need to remember that the object model in Unreal Engine is based on object prototypes, very much like in JavaScript. Each UClass is associated to a default instance of the associated UObject class, called the Class Default Object (CDO), which is allocated first and then constructed, only once, via the class constructor when the engine is initialised. The CDO acts as a template from which all other instances of the class are copied, and the constructor is never called again.
이러한 함수의 차이점을 이해하려면 언리얼 엔진의 객체 모델이 JavaScript와 매우 유사한 Object Prototypes을 기반으로 한다는 점을 기억해야 합니다. 각 UClass는 Class Default Object(CDO)라고 하는 관련된 UObject 클래스의 기본 인스턴스에 연관되며, 이 CDO는 먼저 할당된 다음 엔진이 초기화될 때 클래스 생성자를 통해 단 한 번만 생성됩니다. CDO는 클래스의 다른 모든 인스턴스가 복사되는 템플릿 역할을 하며 생성자는 절대 다시 호출되지 않습니다.
This means class constructors cannot contain any runtime logic, and should only be used to initialise the CDO and its properties. If the class contains any subobjects, like actor components, these must do the same, so their own default objects must be constructed first. The actual instantiation of the object must then be deferred, after the engine has initialised, so that every time a new instance of the class is requested to be created by normal gameplay code, the parent object and all of its subobjects are instantiated from their respective defaults.
즉, 클래스 생성자는 런타임 로직을 포함할 수 없으며 CDO와 해당 프로퍼티를 초기화할 때만 사용해야 합니다. 클래스에 액터 컴포넌트와 같은 서브 오브젝트가 포함된 경우, 이 서브 오브젝트도 동일한 작업을 수행해야 하므로 자체 Default Object를 먼저 생성해야 합니다. 그런 다음 오브젝트의 실제 인스턴스화는 엔진이 초기화된 후에 연기되어야 하므로 일반 게임플레이 코드에서 클래스의 새 인스턴스 생성을 요청할 때마다 부모 오브젝트와 모든 서브오브젝트가 각각의 기본값으로 부터 인스턴스화됩니다.
So, the multiple ways of creating objects are necessary to handle all the different scenarios where an object may be created.
따라서 오브젝트가 생성될 수 있는 다양한 시나리오를 모두 처리하려면 오브젝트를 생성하는 여러 가지 방법이 필요합니다.
UObject::CreateDefaultSubobject is only callable in a class constructor, and takes care of creating an instance of the CDO of the subobject's class, setting its outer class as the caller object, among other things. The created object then becomes the default object for the property when its object class is instantiated.
UObject::CreateDefaultSubobject는 클래스 생성자에서만 호출할 수 있으며, subobject 클래스의 CDO 인스턴스를 생성하고 그것의 Outer 클래스를 caller object로 설정하는 등의 작업을 처리합니다. 그런 다음 생성된 object는 해당 object class가 인스턴스화될 때 프로퍼티의 Default Object가 됩니다.
NewObject<T> is the function normally used to instantiate objects after engine initialisation, during normal gameplay. It provides several convenience overloads to handle most scenarios.
NewObject<T>는 보통 엔진 초기화 후 일반적인 게임플레이 중에 오브젝트를 인스턴스화하는 데 사용되는 함수입니다. 이 함수는 대부분의 시나리오를 처리하기 위한 몇 가지 편리한 오버로드를 제공합니다.
UWorld::SpawnActor<T> is a convenience method to spawn actors in a level with the specified location and rotation, spawn collision settings, and checks to ensure it's a spawnable actor class, and is nothing more than a wrapper of NewObject<AActor>.
UWorld::SpawnActor<T>는 레벨에서 지정된 location과 rotation으로 액터를 스폰하고, 콜리전 설정을 스폰하고, 스폰 가능한 액터 클래스인지 확인하는 편리한 메서드이며, NewObject<AActor>의 래퍼에 불과합니다.
I recommend checking the engine source code for more information, especially UObject/UObjectGlobal.cpp and UObject/UObjectGlobal.h in the CoreUObject engine module. Internally, all these function ultimately call (as of 4.24) StaticConstructObject_Internal, which handles the actual object creation.
자세한 내용은 엔진 소스 코드, 특히 CoreUObject 엔진 모듈의 UObject/UObjectGlobal.cpp와 UObject/UObjectGlobal.h를 확인하는 것이 좋습니다. 내부적으로 이 모든 함수는 궁극적으로 (4.24 버전부터) 실제 오브젝트 생성을 처리하는 StaticConstructObject_Internal을 호출합니다.
[ Reference ]
'UE5' 카테고리의 다른 글
[UE5] 공식 문서 주요사항 메모 (0) | 2024.11.19 |
---|---|
[UE5] TWeakObjectPtr (4) | 2024.11.06 |
[UE5] LineTrace Cost (3) | 2024.10.18 |
[UE5] Widget Blueprint가 추가된 후 보이지 않음 (0) | 2024.07.29 |
[UE5] UE_LOG, FName (0) | 2024.07.25 |