Announcement

Collapse
No announcement yet.

How to change skeletalmesh and animblueprint at runtime?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to change skeletalmesh and animblueprint at runtime?

    Hi.
    I have started this question on answerhub, but did not get answer.
    https://answers.unrealengine.com/que...int-at-ru.html

    Maybe here someone can answer, if he tried same thing to do.

    The main idea is to change mesh and animations in same blueprint, and not spawn new another blueprint of same class whith same parameters and only with different skeletal mesh and animations.

    class .h
    Code:
     
    UPROPERTY(VisibleDefaultsOnly, Category = Mesh)
    TSubobjectPtr<USkeletalMeshComponent> CurrentMesh;
     
    UPROPERTY(EditDefaultsOnly, Category = Mesh)
    USkeletalMesh* FlagMesh;
     
    UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Animation)
    UAnimBlueprint* FlagVIM;
    class .cpp
    Code:
    CurrentMesh->SetSkeletalMesh(FlagMesh); //works
    CurrentMesh->SetAnimClass(FlagVIM->GetAnimBlueprintGeneratedClass()); //fails
    So, i do not understand what to pass to Mesh->SetAnimClass() as parameter UCLASS*, because all my tries failed.

    #2
    Still no answer is.
    No one tried to do same thing?

    Comment


      #3
      Hi _h2o_,

      I'd really expect the code you pasted to work as expected, unless the skeleton of FlagMesh and FlagVIM do not match.

      Can you set a breakpoint after the call to SetAnimClass, and inspect CurrentMesh to see what the value of AnimScriptInstance is? Also double-check the value of FlagMesh->Skeleton and FlagVIM->GeneratedClass->TargetSkeleton are as you expected.


      You can also try setting AnimationMode = EAnimationMode::Type::AnimationBlueprint and AnimBlueprintGeneratedClass to FlagVIM->GetFoo directly.

      Cheers,
      Michael Noland

      Comment


        #4
        Tnx for reply Michael Noland

        You can also try setting AnimationMode = EAnimationMode::Type::AnimationBlueprint and AnimBlueprintGeneratedClass to FlagVIM->GetFoo directly.
        SetAnimClass() as i can see do all this things and also recreates new animinstance. So i do not sure that direct AnimBlueprintGeneratedClass setting will be correct, because AnimInstance will be old and wrong.

        I have done additional investigation - and i was wrong.
        Code:
        CurrentMesh->SetSkeletalMesh(FlagMesh); //works
        CurrentMesh->SetAnimClass(FlagVIM->GetAnimBlueprintGeneratedClass()); //works too
        After the line CurrentMesh->SetSkeletalMesh(FlagMesh) i got this message:
        LogAnimation:Warning: AnimBP p_dominanceFlag_01_AnimBlueprint_C is incompatible with skeleton p_dominanceFlag_02_Skeleton, removing AnimBP from actor.
        But in VS debug after second line CurrentMesh->SetAnimClass(FlagVIM->GetAnimBlueprintGeneratedClass()); it looks like it set right:


        So, to change skeletal mesh i need to do something else before call SetSkeletalMesh().
        I remember that some time ago i saw in answerhub thread where epic support answered that it is not needed to recreate USkeletalMeshComponent, just need to SetSkeletalMesh(), but should be also something else to clear old mesh and then set new one.

        As, it looks like SetAnimClass() works proper, than animation do not work with different reason. So here is just one last question, how to correct change skeletal mesh to not have animBp conflict.

        Comment


          #5
          Originally posted by _h2o_ View Post
          After the line CurrentMesh->SetSkeletalMesh(FlagMesh) i got this message:
          LogAnimation:Warning: AnimBP p_dominanceFlag_01_AnimBlueprint_C is incompatible with skeleton p_dominanceFlag_02_Skeleton, removing AnimBP from actor.
          This is the actual error, the skeletons don't match. You can solve it in a couple of different ways, depending on exactly how your meshes are set up. Do both flag meshes have the same number of bones and are they named the same? If so (or if one flag has the same bones at the root, but additional leaf bones), then you can make the share the same skeleton. The easiest way is to reimport the second mesh and when importing pick the Skeleton of the first mesh (the one that you already made FlagVIM for). You'll also need to remport any animations that target the second flag.

          Cheers,
          Michael Noland

          Comment

          Working...
          X