Hi, I am trying to make an event triggered in C++ so that you can handle states in the animation blueprint (AnimInstance).
I am trying to make it work for a AI bot, lets say we want to trigger Attack state,
so first I created a new class extending from “AIController”, this class determines the behavior of my AI Bot.
Next I created a class extending from “AnimInstance”:
#include "Animation/AnimInstance.h"
#include "JurijAnimationInstance.generated.h"
UCLASS(transient, Blueprintable, hideCategories = AnimInstance, BlueprintType)
class UJurijAnimationInstance : public UAnimInstance
{
GENERATED_UCLASS_BODY()
public:
UFUNCTION(BlueprintImplementableEvent, meta = (FriendlyName = "PlayOrStopAttackAnimation"))
virtual void PlayAttackAnimation(bool IsAttacking);
};
This creates an Event you can add in your blueprint (extending from this class), so that you can trigger from code when the animation states will change.
My problem is that I need to trigger this function from my AIController class, and I don’t know how to make a pointer to it.
I have been trying and I know it shouldn’t be that hard , I hate to admit but I seem to be missing something, code compiles but my event never gets triggered from AIController.
This is a failed attempt, first the header:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement)
TSubobjectPtr<class UJurijAnimationInstance> TriggerTheEvent;
Then I initialize it in .cpp:
TriggerTheEvent = PCIP.CreateDefaultSubobject<UJurijAnimationInstance>(this, TEXT("AnimInstanceSender"));
and call it like this :
TriggerTheEvent->PlayAttackAnimation(true);
I have also tried using * to point to class , but in the debug it said function is not allowed to call.
I am somewhat new to pointers so thanks a bunch to anyone who replies.
If I extend on this question, lets say we want to make a selectable AI Bot, so while having all the behavior of an AI Bot,
we want to be able to control the bot using our own controller. Like for example in strategy games. How would I tackle this?
Should I include the AIController class in MyController class ? and make pointers to be able to call its functions?
I believe it is a same problem. Thanks!!!