Get reference to UClass type from a class

Is there a way to get a reference to a UClass* type from an ordinary class instead of an object?

The most common way is to use GetClass() function but for that to happen I must have an object or a pointer to an object first. But the problem is, I don’t have an object or a pointer in my current class implementation.

For example suppose I have ABall class and APerson class. Then I want to do something like this (CollisionSphere is of type USphereComponent attached to APerson object):

> void APerson::TouchBall() 
> {
>     TArray<AActor*> BallsInRange;
>     CollisionSphere->GetOverlappingActors(BallsInRange, ABall::GetClass());
> }

The second parameter of GetOverlappingActors() is of type UClass* which can filter out all actors in the game. That code is incorrect, but I think you get the point. How can I achieve something like this?

Thanks.

1 Like

It turns out there’s a StaticClass() function that every UObject derived class has.

1 Like