How to add base functionality to Actor?

Actor comes with a bunch of stuff that’s quite specific to the type of game that’s traditional to Unreal like OnTakeAnyDamage and OnTakePointDamage.

For our game though, we have a very different set of fundamentals. A basic event would be something like OnInteract or OnSeen. Every single Actor in our game that has any gameplay attached to it would have those.

The natural way of going about this would be to subclass Actor. The problem with that though is that I’d still like to use Pawns, Characters and all the good stuff that derives from Actor. If I subclass Actor, then I won’t be able to have an NPC character that also has OnInteract, etc.

One way to approach this would be to take a component-based approach and add all this base functionality in components. Coming from a Unity background, I’m quite used to this. However, after spending two weeks with components, I’ve been extremely frustrated with all the limitations that components have when compared to Unity components (no way to hook into their EventDispatchers directly from the level, no way to call their events / functions directly without referencing the Owner first and then iterating through all its components, no way to add a timeline to their blueprint, no way to reference a component from the editor details panel, etc. etc). There’s just so much you can do with an Actor that you can’t do with a component. Everything in Unreal seems to be very Actor-centric.

Another approach would be to leave Characters as they are, but add all the gameplay functionality to a separate Actor that I attach to the Character in the hierarchy. But this is limited too. Any raycasts for example would be hitting the character and not the Actor attached to it.

Perhaps I’m just trying to approach things the wrong way. Would welcome suggestions on how to approach this in a good Unreal-y way. Thanks! :slight_smile:

Why, you can, just subclass all you NPC’s from your Actor.
You should consider that AActor is not just for players - it is a base type for all actors, like scene cameras and static meshes, lights and other engine stuff.
The main Actor for game characters is APawn and ACharacter classes, so you should extend those.

And next thing you should consider - is component based architectures of Unreal Engine - so the main functionality is located in PlayerController and other classes, of which Player Actor is usually build. So main game logic should be implemented with those.

For AI there is new AI behaviour classes, which I have’nt used yet.

Usually subclassing will be enough for all your needs, In raycast you can check and upcast Hit actors to your base class without a problem.

Thanks :slight_smile: But I need to subclass from Actor because not all gameplay objects I interact with will be Characters. If I subclass Character and add OnInteract to that, I can’t get that functionality on a book or a rock which is not a character. A rock or a book will not need a skeletalmesh or a Movement component or any of the other things that Character defines.

Generally book or a rock should be implemented as Pawns. Actors are more generic than gameplay objects. Actors are good for noninteractive decoration items. And Pawns are for everything more complex.

I think i’d start with making some common actor or scene component, which will implement all the logic of firing OnInteract events. And add it to all my gameobjects. Than there should be interface to get to this component.

Of course there is always the option to get the source code of UE and add needed functionality to base classes, but I’d avoid doing this. It is easy to build UE yourself, but changing base classes is an overkill.

Check Fortnite, UT and ARK devkits - these are games based on UE, I dont think they are chengin the Engine too much.

No, Books and Rocks should be Actor, Pawn is for controllable objects which PlayerController or AIController or any other Controller can posses

Yes, , is definitely right. Pawn a for “creature” objects.

Hello kLy did you found a solution to add base functionality to Actor?