[UE4] Static/Dynamic Object 생성 방법.
2015. 12. 11. 01:13 in Programming/UE4

* SkeletalMesh를 이미 UE4 Editor를 통해 만들었을 때를 기준으로 함
튜토리얼 및 대부분의 정보는 AActor클래스를 상속받은 액터 클래스 내부에서 ConstructorHelper::FObjectFinder를 통하여 생성된 Mesh를 읽어들이게 가이드 하고 있다.
- {
- static ConstructorHelpers::FObjectFinder< USkeletalMesh > NewMesh( TEXT( "/Game/SkeletalMeshPath" ) );
- if( NewMesh.Succeeded() )
- {
- /* below code is using if this block is class of component */
- SetSkeletalMesh( NewMesh.Object );
- /* If this code block is class of actor, should use like below code.
- Component->SetSkeletalMesh( NewMesh.Object );
- */
- }
- }
문제는 모든 메시별 클래스를 만들어줄 것인가? 에서 부터 시작되었는데, 만들어진 Mesh Path의 문자열만 가지고 Component object를 위한 Skeletal Mesh를 Actor loading단계에서 불러오고 싶은데, ConstructorHelper::FObjectFinder를 사용하게 되면 다음의 Crash 에 직면하게 된다.
(이런건 좀 튜토리얼 레벨에서 알려주면 안되나...)
- void ConstructorHelpers::CheckIfIsInConstructor(const TCHAR* ObjectToFind)
- {
- auto& ThreadContext = FUObjectThreadContext::Get();
- UE_CLOG(!ThreadContext.IsInConstructor, LogUObjectGlobals, Fatal, TEXT("FObjectFinders can't be used outside of constructors to find %s"), ObjectToFind);
- }
해결방법은 다음의 소스코드를 사용하면 해결된다. (삽질한 시간대비 참 허무한 결과...)
- void UEquipment::SetContentMesh( const TCHAR* ContentPath )
- {
- USkeletalMesh* NewMesh = Cast< USkeletalMesh >( StaticLoadObject( USkeletalMesh::StaticClass(), NULL, ContentPath ) );
- if( NewMesh )
- {
- SetSkeletalMesh( NewMesh );
- }
- }
참고자료 : https://wiki.unrealengine.com/Dynamic_Load_Object