In c++ how do I get a component from another class from my player character

For example if I wanted to get a text renderer component from another actors class how would i go about that?

I’ve tried GetComponentByClass, TSubclassOf and many more methods involving those 2

for a bit more context, I’ve created an actor class in C++ then created a blueprint from it, within that blueprint I’ve added a text renderer and placed it where i want it relative to the actor.

I would like to access that text renderer from my player character through C++.

Thank you in advance! Sorry if its a simple question I’m still quite new to UE4

Hey there, this code finds all TextRenderComponents on an Actor and prints the Text value. This will work regardless of the TextRenderComponent being placed in C++ or BP

In your scenario you want to access at Parent level (C++ class) something what was added on Child level (BP class based on your C++ class). Most of the time it’s against Object-Oriented Programming and it should give you a hint that maybe something wrong is going on with your architecture. It’s doable but I would strongly suggest not doing that. If possible I would think about moving the text renderer to Parent (C++ class) and make it editable from blueprint so you will be able to place it wherever you want directly in blueprint.

This is exactly what I’ve been looking for thank you! I hate how little support there is for newcomers to UE4 who just want to use c++. The lack of example code is such a pain! Thank you again this has solved my problem completely