코가손의 블로그
언리얼C++ 오브젝트 생성, 애셋 레퍼런싱, 애셋 로딩 본문
UObject생성
AActor
T* UWorld::SpawnActor(
FVector const& Location,
FRotator const& Rotation,
const FActorSpawnParameters& SpawnParameters
)
UClass
LoadClass<T>(NULL, TEXT("Game/....", NULL, LOAD_None, NULL);
UObject
template<class T>
T* NewObject(
UObject* Outer = (UObject*)GetTransientPackage(),
UClass* Class = T::StaticClass()
)
애셋 레퍼런싱
경로 지정시 Content/는 Game/으로
경로 : Project/Content/Character/MyCharacter.uasset
>> /Game/Character/MyCharacter
에디터에서 CopyReference시 내용
[Description]'[LongPackageName].[AssetName]'
- Description : Texture2D, WidgetBlueprint, SkeletalMesh, ...
- LongPackageName : /Game/Character/MyCharacter
- AssetName : MyCharacter
실제Path VS 언리얼의 Ref Path
Path : Project/Content/Character/MyCharacter.uasset
Ref Path : Description'/Game/Character/MyCharacter.MyCharacter'
+ Blueprint Path : /Game/Character/MyCharacter_C
- (블루프린트 클래스의 경우 다른 오브젝트와 구분 용도로 _C를 붙임)
파일로 레퍼런싱 관리
Default[GameTitle].ini 파일 생성
[/Script/ArenaBattle.ABCharacterNonPlayer]
+NPCMeshes=/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_Barbarous.SK_CharM_Barbarous
+NPCMeshes=/Game/InfinityBladeWarriors/Character/CompleteCharacters/sk_CharM_Base.sk_CharM_Base
+NPCMeshes=/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_Bladed.SK_CharM_Bladed
+NPCMeshes=/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_Cardboard.SK_CharM_Cardboard
+NPCMeshes=/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_Forge.SK_CharM_Forge
+NPCMeshes=/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_FrostGiant.SK_CharM_FrostGiant
+NPCMeshes=/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_Golden.SK_CharM_Golden
+NPCMeshes=/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_Natural.SK_CharM_Natural
+NPCMeshes=/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_Pit.SK_CharM_Pit
+NPCMeshes=/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_Ragged0.SK_CharM_Ragged0
+NPCMeshes=/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_RaggedElite.SK_CharM_RaggedElite
+NPCMeshes=/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_Ram.SK_CharM_Ram
+NPCMeshes=/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_Robo.SK_CharM_Robo
+NPCMeshes=/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_Shell.SK_CharM_Shell
+NPCMeshes=/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_solid.SK_CharM_solid
+NPCMeshes=/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_Standard.SK_CharM_Standard
+NPCMeshes=/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_Tusk.SK_CharM_Tusk
+NPCMeshes=/Game/InfinityBladeWarriors/Character/CompleteCharacters/SK_CharM_Warrior.SK_CharM_Warrior
// 생성한 DefaultGameTitle.ini파일을 이용할 수 있음
UCLASS(config=GameTitle)
class GAMETITLE_API AABCharacterNonPlayer : public AABCharacterBase
{
GENERATED_BODY()
public:
AABCharacterNonPlayer();
protected:
UPROPERTY(config)
TArray<FSoftObjectPath> NPCMeshes;
TSharedPtr<FStreamableHandle> NPCMeshHandle;
}
// .cpp
{
// 비동기 로딩 + 로딩 종료함수 바인딩
NPCMeshHandle.UAssetManager::Get().GetStreamableManager().RequestAsyncLoad(NPCMeshes[원하는인덱스], ..., &ThisClass::로드종료함수);
}
애셋 로딩
생성자 로딩
언리얼Path를 통해 애셋 로드, 없으면 nullptr반환
- ConstructorHelpers::FObjectFinder
- ConstructorHelpers::FClassFinder
런타임 로딩
UObject* StaticLoadObject(
UClass* Class,
UObject* InOuter,
const TCHAR* Name,
const TCHAR* FileName,
uint32 LoadFlags,
UPackageMap* Sandbox,
bool bAllowObjectRecociliation
)
UObject* LoadObjectFromPath(const FName& path)
{
if( path == NAME_None) return NULL;
return Cast<UObject>(StaticLoadObject( UObject::StaticClass(), NULL, *path.ToString());
}
LoadObject<T>(NULL, TEXT("Game/....", NULL, LOAD_None, NULL);
}
Blueprint로딩
TSubclassOf<AActor> SpawnedClass;
FString SpawnedBlueprintReference = TEXT("Blueprint'/Game/FirstPersonCPP/Blueprints/FirstPersonProjectile.FirstPersonProjectile'");
UObject* LoadedObject = StaticLoadObject(UObject::StaticClass(), nullptr, *SpawnedBlueprintReference);
UBlueprint* CastedBlueprint = Cast<UBlueprint>(LoadedObject);
if (CastedBlueprint && CastedBlueprint->GeneratedClass->IsChildOf(AActor::StaticClass()))
{
SpawnedClass = *CastedBlueprint->GeneratedClass;
}
서브오브젝트 얻어오기
// GetDefaultSubobjects사용
TArray<UObject*> Objects;
GetDefaultSubobjects(Objects);
// FActorRange사용
UWorld* World = GetWorld();
FActorRange Range(World);
// TActorIterator사용하여 특정타입만 얻어올 수 있음
// TActorIterator<액터타입> Iter(World);
for (const auto& Actor : Range)
{
//...
}
액터에서 컴포넌트 검색
Actor->FindComponentByClass<U컴포넌트>();
'GameDevLog > UnrealEngine5' 카테고리의 다른 글
언리얼 게임 프레임워크 (0) | 2023.06.21 |
---|---|
[ DevLog ] MultiplayerShooter#05 멀티 환경의 무기 픽업 위젯 띄우기(Repilicate, RepNotify) (0) | 2023.04.17 |
[ DevLog ] MultiplayerShooter#04 유저 접속 (0) | 2023.04.14 |
[ DevLog ] MultiplayerShooter#03 발광 텍스쳐 (0) | 2023.04.14 |
[ DevLog ] MultiplayerShooter#02 입력방향을 따라 회전하는 캐릭터 (0) | 2023.04.14 |
Comments