0
\$\begingroup\$

How to set the hair mesh to follow the animation? I am trying this.

.cpp
Hair = CreateDefaultSubobject<USkeletalMeshComponent>("Hair");
    Hair->SetupAttachment(GetMesh());
    Hair->AttachToComponent(MyCharacter::GetMesh(), FAttachmentTransformRules::KeepWorldTransform, TEXT("head"));

.h
UPROPERTY(EditAnywhere, Category = "Components")
    class USkeletalMeshComponent* Hair;

RESULT

I have attached the hair mesh to the Head socket but the hair mesh is not following the animation. The hair mesh is called Hair_Mesh and has been attached in the editor while the Hair skeletal mesh component is already sets to UPROPERTY(EditAnywhere, Category = "Components")

\$\endgroup\$
0
\$\begingroup\$

By the looks of it, the hair is attaching to the mesh but isn't animating.

You can set the Hair component to use the animation of the mesh by calling it's Master Pose Component.

Hair->SetMasterPoseComponent(GetMesh());

You put this in your cpp constructor under where you've attached it to the mesh.

\$\endgroup\$
3
  • \$\begingroup\$ Not working for me ( \$\endgroup\$
    – josil
    May 21 at 13:15
  • \$\begingroup\$ What happens if you remove or comment out the line beginning Hair->AttachToComponent ? \$\endgroup\$
    – Stephen
    May 21 at 15:37
  • \$\begingroup\$ After commenting this line the Hairs mesh is not following the head and animations in the lobby, and when un-commenting the line, the hairs mesh is following the head only in the lobby but in the editor not following. \$\endgroup\$
    – josil
    May 21 at 16:11
-1
\$\begingroup\$
**.h**
UPROPERTY(BlueprintReadWrite, NonTransactional, meta = (Category = "Default", OverrideNativeName = "Hair"))
        USkeletalMeshComponent* Hair;
    UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, meta = (DisplayName = "Skin Met R", Category = "SkeletalMesh", MultiLine = "true", OverrideNativeName = "SkinMetR"))
        UMaterialInstanceDynamic* SkinMetR;
    AMyCharacter(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
    virtual void PostLoadSubobjects(FObjectInstancingGraph* OuterInstanceGraph) override;
    static void CustomDynamicClassInitialization(UDynamicClass* InDynamicClass);
    static void StaticDependenciesAssets(TArray<FBlueprintDependencyData>& AssetsToLoad);
    static void StaticDependencies_DirectlyUsedAssets(TArray<FBlueprintDependencyData>& AssetsToLoad);
virtual void UserConstructionScript();
    UFUNCTION(BlueprintCallable, meta = (Category = "SkeletalMesh", OverrideNativeName = "InitSkeletalMesh"))
        virtual void InitSkeletalMesh()


**.cpp**
void AMyCharacter::InitSkeletalMesh(){
bool CallFunc_K2_AttachToComponent_ReturnValue{};
    if(::IsValid(Hair))
    {
        CallFunc_K2_AttachToComponent_ReturnValue = Hair->USceneComponent::K2_AttachToComponent((*(AccessPrivateProperty<USkeletalMeshComponent* >((this), ACharacter::Mesh() ))), FName(TEXT("head")), EAttachmentRule::KeepWorld, EAttachmentRule::KeepWorld, EAttachmentRule::KeepWorld, true);
    }
}
\$\endgroup\$
2
  • \$\begingroup\$ Not working for me ( \$\endgroup\$
    – josil
    May 21 at 13:15
  • 1
    \$\begingroup\$ Welcome to GDSE & thankyou for contributing. This answer could be improved by include an explanation of how it solves the problem & why you included these particular steps. \$\endgroup\$
    – Pikalek
    May 23 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.