Once Per Tick Global Processing

Looking for best-practices here.

We need to have a function called once per game tick globally. It does things like relaxes crowd sound instance counts to prevent spamming sound, NPC respawn throtteling etc.

I have implemented it as a C++ AActor subclass, and a blueprint off of that. Then we have just one in the map.

Is this the best way to do this?

I looked for UGameInstance for OnTick, or ReceiveTick or similar functuins and don’t see them.

AGameMode will tick, but if you’re game is multi-player it’s worth noting that GameModes only exist on the server/authority. You could tell it to fire an event in a GameState however, but that’ll be pretty network intensive if you’re doing it per-tick. Hard to say what the best approach would be without a few more details :slight_smile:

I think the way you’ve done it is OK actually. In the level blueprint you can spawn your global actor when begin play on the level is called. Do a search for any actors of that class beforehand and destroy them so that you enforce the single actor.

GameInstance does not come with a Tick function built in, but you can make tickable by subclassing FTickableGameObject:


class UMyGameInstance : public UGameInstance, public FTickableGameObject

The FTickableGameObject interface provides a few different ways to control ticking behaviour. It automatically takes care of registering the object with the tick manager so you don’t have to worry about any of that.

Can you actually do multiple inheritance with UObjects? I thought it only supported multiple inheritance with interfaces and would fail to compile otherwise. This sounds like it may be doable with just a single AActor that exists in the game that isn’t a GameMode. Maybe like a special AActor that inherits from AInfo and controls this on clients and servers.