I’m trying to figure out how FindComponentByClass works by treating it roughly analogously to Unity’s GetComponent() function, I know I’m absolutely butchering the code but I’d appreciate a bit of help figuring out what I’m doing wrong. I’m running this in a class CharacterPerception that lives on the player’s Actor, and I’m trying to set myPerceptionComponent equal to a reference to the AI Perception component that’s on the root Actor, so I can call myPerceptionComponent.
AIPerceptionComponent* myPerceptionComponent = this->FindComponentByClass<AIPerceptionComponent>();
This produces a boatload of errors:
error C2059: syntax error : ‘)’
error C2065: ‘AIPerceptionComponent’ : undeclared identifier
error C2065: ‘myPerceptionComponent’ : undeclared identifier
error C2355: ‘this’ : can only be referenced inside non-static member functions or non-static data member initializers
error C2227: left of ‘->FindComponentByClass’ must point to class/struct/union/generic type
I assume the undeclared identifier stuff means that AIPerceptionComponent isn’t the name the engine uses for the Perception component, although right-clicking it in the editor directs me to AIPerceptionComponent.h, but I’m not sure where to start unfrazzling the rest of my syntax.