Calling a function/method from an empty C++ Class

Hi everyone,

I’m currently developing an algorithm in C++ for my game, and I am writing the code in an empty C++ (not actor, scene, etc).
Now I want to call the method in my Scene Component class (inherited from Scene Component), but it always says “A non-static member reference must be relative to a specific object”.

Let’s say my class is ABC, and my method is CheckABC().

So currently I’m calling the method in the Scene Component class through ABC::CheckABC(), which returned the aforementioned error message.

I found in the forum that we have to create a default subobject, but since that ABC class is an empty class, it would be nonsense to create a subobject from it, wouldn’t it?

Thanks in advance!!

This may sound dumb, I’m guessing you probably checked this first, but asking doesn’t hurt: did you make the method static? Meaning, if you really don’t want to create an object (though you may use a singleton architecture), did you specified your class’s methods as static?

No, I forgot to… And it works… Perhaps I got confused because when it happened last time in another case, I needed to create the default subobjects. Thanks for the help!!!

Create Default subobjects works for UE derived classes. Tbh I don’t quite know how it works, but I think it calls the initializer (AClass()) and automatically inserts the traditional FObjectInitializer variable so you don’t have to do it yourself.

Whenever you use the “::” sign in Cpp you are calling a static method.
Working with static classes in Unreal is a little confusing at first, but its great to avoid objects when not needed; you can fire Broadcast() events from static delegates and subscribe static functions to TimerManager using the method to create static bindings, I’ve found this possibility very very useful when I need to avoid creating UObjects.

But can I then call a blueprint function from that empty class? Since it’s not an Unreal Object after all…