Download

What is the best base class for a generic spawner class?

Hello everyone.

So, I’m very new to Unreal and most of my knowledge base comes from Game Maker. I am not very familiar with the base classes included in Unreal.

My goal in my current project is to have a class that regularly spawns obstacles that move across the screen. As time goes on, the obstacles get faster and spawn in faster intervals.

I decided to try and generate a completely blank class. I think I got a good start, but then I realized that it did not include a Tick() method, which I would need in order to increment the spawn timers and the speeds at which to send the generated obstacles.

What *.h files do I need to #include in order to have a functioning Tick() method?

The base class for objects that exist independently in the world is AActor, which can tick.

1 Like

Okay. So if I add

#include "GameFramework/Actor.h"

to my *.h file, and add

virtual void Tick(float DeltaTime) override;

under the “public” declaration, I can have my Tick function? No added macros required?

Your class needs to descend from AActor or something that descends from AActor.

Also, read Actor Ticking | Unreal Engine Documentation

To inherit AActor, your class declaration needs to be

UCLASS(<might want things in here, like Blueprintable>)
class MYMODULENAME_API AGenericSpawner : public AActor
{
    GENERATED_BODY()
    //...
};

Stuff to note there is the : public AActor and the A prefix for your class name.