How can pure C++ class call functions of Actor Class?

I have a actor who has a drawSphere() function to draw a sphere in world, and a pure C++ class named SkelPoint.

In SkelPoint I want a sphere drawing function, in other word, I want to call drawSphere() belonging to the actor.

Because the actor draw spheres by runtime mesh component, I can’t just include its header. I need the instance of that actor.

I don’t want the pure C++ class include any Unreal things, so I tried to create a new class to communicate with Unreal. In the new class I take a pointer of the actor as its member. I want to expose it by UPROPERTY so I can set up the pointer in editor. But the class can’t be seen in editor because it inherits nothing from Unreal. If it inherits something like actor then the problem comes back.

I don’t know how to solve this, can someone teach me how?

Thanks a lot.

Maybe consider to sub class from UObject instead of a blank class.

If you want something to be exposed to the editor it must be a part of an Object or an Actor. If you are implementing something in a pure C++ class that usually means that you don’t want it to be managed by the engine so you need your own initialization/configuration etc.

The C++ class can find the Actor with a call to UGameplayStatics:: or using TActorIterators.

Thank you all. I will try the methods.:slight_smile:

We have many barebones C++ classes that can call Unreal objects in the following way:

  • add the barebones class in the Editor with Add New C++ Class >> Empty Class
  • in the .h files forward declare any Unreal classes it needs to interact with
  • in the .cpp files #include header files of any Unreal classes you use