Can now switch the skeletal mesh on a character
This commit is contained in:
@@ -627,45 +627,43 @@ void UlxAnimationStepLibrary::AnimationStepApplyMaterials(const FlxAnimationStep
|
||||
}
|
||||
}
|
||||
|
||||
void UlxAnimationStepLibrary::AnimationStepApplyMesh(const FlxAnimationStep& step, bool FallbackToBP, AActor* actor) {
|
||||
if (actor == nullptr) return;
|
||||
void UlxAnimationStepLibrary::AnimationStepApplyStaticMesh(const FlxAnimationStep& step, bool FallbackToBP,
|
||||
UStaticMeshComponent* MeshComp, UStaticMesh* Fallback) {
|
||||
if (MeshComp == nullptr) return;
|
||||
|
||||
// Step 1: Look for a "mesh" or "bp" string field in the animation step.
|
||||
//
|
||||
FString MeshName = AnimationStepGetString(step, TEXT("mesh"));
|
||||
if (MeshName.IsEmpty() && FallbackToBP) {
|
||||
MeshName = AnimationStepGetString(step, TEXT("bp"));
|
||||
}
|
||||
if (MeshName.IsEmpty()) return;
|
||||
|
||||
// Step 2: Find the actor's mesh component. There must be exactly one.
|
||||
//
|
||||
TInlineComponentArray<UMeshComponent*> MeshComponents;
|
||||
actor->GetComponents<UMeshComponent>(MeshComponents);
|
||||
if (MeshComponents.Num() != 1) {
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("AnimationStepApplyMesh: Actor %s has %d mesh components, expected exactly 1"), *actor->GetName(), MeshComponents.Num());
|
||||
return;
|
||||
UStaticMesh* NewMesh = nullptr;
|
||||
if (!MeshName.IsEmpty()) {
|
||||
UlxAssetLookup::LoadStaticMeshAsset(NewMesh, MeshComp, MeshName);
|
||||
}
|
||||
UMeshComponent* MeshComp = MeshComponents[0];
|
||||
|
||||
// Step 3: Apply the mesh based on the component type.
|
||||
//
|
||||
if (UStaticMeshComponent* StaticComp = Cast<UStaticMeshComponent>(MeshComp)) {
|
||||
UStaticMesh* NewMesh = nullptr;
|
||||
UlxAssetLookup::LoadStaticMeshAsset(NewMesh, actor, MeshName, false);
|
||||
if (NewMesh == nullptr) return;
|
||||
if (StaticComp->GetStaticMesh() != NewMesh) {
|
||||
StaticComp->SetStaticMesh(NewMesh);
|
||||
}
|
||||
} else if (USkeletalMeshComponent* SkelComp = Cast<USkeletalMeshComponent>(MeshComp)) {
|
||||
USkeletalMesh* NewMesh = nullptr;
|
||||
UlxAssetLookup::LoadSkeletalMeshAsset(NewMesh, actor, MeshName, true);
|
||||
if (NewMesh == nullptr) return;
|
||||
if (SkelComp->GetSkeletalMeshAsset() != NewMesh) {
|
||||
SkelComp->SetSkeletalMeshAsset(NewMesh);
|
||||
}
|
||||
} else {
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("AnimationStepApplyMesh: Actor %s has unsupported mesh component type"), *actor->GetName());
|
||||
if (NewMesh == nullptr) NewMesh = Fallback;
|
||||
if (NewMesh == nullptr) return;
|
||||
if (MeshComp->GetStaticMesh() != NewMesh) {
|
||||
MeshComp->SetStaticMesh(NewMesh);
|
||||
}
|
||||
}
|
||||
|
||||
void UlxAnimationStepLibrary::AnimationStepApplySkeletalMesh(const FlxAnimationStep& step, bool FallbackToBP,
|
||||
USkeletalMeshComponent* MeshComp, USkeletalMesh* Fallback) {
|
||||
if (MeshComp == nullptr) return;
|
||||
|
||||
FString MeshName = AnimationStepGetString(step, TEXT("mesh"));
|
||||
if (MeshName.IsEmpty() && FallbackToBP) {
|
||||
MeshName = AnimationStepGetString(step, TEXT("bp"));
|
||||
}
|
||||
|
||||
USkeletalMesh* NewMesh = nullptr;
|
||||
if (!MeshName.IsEmpty()) {
|
||||
UlxAssetLookup::LoadSkeletalMeshAsset(NewMesh, MeshComp, MeshName);
|
||||
}
|
||||
if (NewMesh == nullptr) NewMesh = Fallback;
|
||||
if (NewMesh == nullptr) return;
|
||||
if (MeshComp->GetSkeletalMeshAsset() != NewMesh) {
|
||||
MeshComp->SetSkeletalMeshAsset(NewMesh);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user