0
\$\begingroup\$

This is my first leap out of tutorials and building my own game so bear with me. I've been struggling with getting C++ classes to work with one another and accessing Unreal blueprints from my code.

I currently have the Action Bound and logic required for an "attack action" in my Character C++ class. I want to access the C++ UAnimInstance class that I created and is currently parenting my Animation Blueprint for my character so that I can change a bool variable within it - this bool is a requirement in my state machine to begin the attack animation.

How do I access one class from another?

What I Have Tried:

MainCharacter.h:

UCLASS()
class SQUEEGLESADVENTURE_API AMainCharacter : public ACharacter

private:
    class UABP_MainGoblin* GoblinClass;

MainCharacter.cpp

void AMainCharacter::IceAttack()

{

  GoblinClass->bIceAttack = true;

}

I'm getting error "Pointer to incomplete class type "UABP_MainGoblin" is not allowed.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

For anyone who comes across this, I did not find an answer per say.

But, I did find a work around.

I put the logic in my C++ class for the MainCharacter, then exposed a bool variable to blueprints in that class, and then changed that bool based on my C++ logic.

Then, in the event graph of the Animation Blueprint for that character in the engine, I got hold of the MainCharacter class and called that bool variable I had set in the code. Then I used that bool reference to set a new bool I created in the animation blueprint - which I can now use in my ABP_MainCharacter.

So in a round about way, the code is in my Character.cpp and it is setting the bool value that is being used in my character's animation. Likely not the most optimal way to do it (or explain it) but hey, sometimes it's just about what works.

Hope this helps someone!

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .