Getting a custom C++ component from a different C++ Component

Apologies in advance because this is an incredibly noob question. I have searched on the forums but I haven’t found anything that helps me. I can’t seem to figure out the GetComponent<>() of Unity equivalent for Unreal. What I’m trying to do is this -
I have a C++ Class/Component attached to my PlayerController BP called A. I have another C++ Class/component attached to my PlayerCharacter BP called B. I want to access A in B. I have a reference to the PlayerController in ‘B’ but when I try doing a GetComponentByClass() or something on it, I always get a compilation error. I just started with unreal and am not familiar with all the syntax, specially since it is so complicated for some reason.
PS : I know the concept, but I need the exact syntax of getting about it, if possible. Thanks

Not sure of your exact setup and calls, so this might not help (You may want to include your code and errors).

It might be you haven’t included the header for your A Class in the B Class, or you aren’t using the function correctly.

#include "AClass.h"
UAClass* MyAClass = Cast<UAClass>(Controller->GetComponentByClass(UAClass::StaticClass()));
1 Like

This worked! I wasn’t adding ::StaticClass() at the end. Thanks a lot for the help :slight_smile: