Download

Update State Machine from Character class

Hi guys
I’m going to try and explain this as clearly as I think I can…

I’m busy messing around with animation state machine and c++

My state machine currently has these states:
pic1.PNG

on the condition node between idle run to Press Button, I have the condition like so:

pic2.PNG

within my CharacterAnimInstance.h class, I have:




UCLASS()
class THEFORGOTTEN_API UCharacterAnimInstance : public UAnimInstance
{
    GENERATED_BODY()

public:

    UCharacterAnimInstance();

    UPROPERTY(EditAnywhere, BlueprintReadWrite)
        bool IsPressingButton;

};



On my Character class, where I handle all the inputs, I have a function to handle when the user presses “E” (for example).



void AMyCharacter::PressButton()
{

    //Should I update UCharacterAnimInstance.IsPressingButton from here?

}


Now: my question is this. Is it good practice to update the IsPressingButton from the player Character class, or am I over thinking this?

If its the right place to do it, then HOW do I do it. Cause every time I try something, the engine crashes.

please let me know if the question is unclear or if you need more info

Thanks in advance

Ok. I got it working… I wasn’t far off

In my character input function, I just needed to cast the animinstance to an object, and then call the PressButton function.


void AMyCharacter::PressButton()
{

    UCharacterAnimInstance* AnimInstanceRef = Cast<UCharacterAnimInstance>(GetMesh()->GetAnimInstance());
    if (AnimInstanceRef) AnimInstanceRef->PressButton();

}

Easy enough. Let me know if anyone needs more info on this

How do you access specific animation state from the AnimInstance Class ?