-
-
Notifications
You must be signed in to change notification settings - Fork 0
Karma Actor
In the context of game development, there exists a concept of highly versatile object which, at the same time, is the most fundamental level building block. By fundamental we mean a single unit whose parametrisation results in the variety of complex level elements participating in the gameplay. If you are thinking about atoms, or even better, strings, then you know precisely what I am talking about. Just like specific arrangement of different atoms give rise to the molecular structure and so on, different "arrangements" of this versatile object should lead to variety of gameplay elements. Thus we have already found a unifying abstraction for all the games that Karma engine is capable of producing. Following Unreal Engine, we call that object, an Actor.
Unreal Engine has had the privilege(?) of powering some of the finest FPS games of the time along with countably many different genres of games (including Hogwarts Legacy, which I have personally worked for). Thus the final Actor management standard(?), that emerged after after surviving for about twenty five years in the industry, with improvements from the feedback and game evolution, in sync with state of the art, I presume, is what we will understand by replicating the same in Karma.
Spawning Actor (official documentation)
We begin with the concept of SpawnActor. In our discussions, the Actors are spawned in World, which holds a reference to Level containing the list of Actors and variety of World relevant information. With the assumption that World object has been instantiated, we go ahead and look at the definition of AWorld::SpawnActor. The entire process of spawning the Actor can be understood in steps.
- Fist the following series of checks are performed:
- First we check if the specified
Classobject is not null (see the wiki page). TheUClassobject basically tellsUObjectAllocatorhow much memory is to be allocated in the pool and aligned to what boundary. AlsoUClassis the specification of the type ofUObjectbeing spawned. - Then we verify that the object that we are going to spawn is some child class of type
AActor. FunctionIsChildOfbasically traverses through all the class, up in the hierarchy, and compares against the argument class to see if same class appears, up in the hierarchy.
if (!Class->IsChildOf(AActor::StaticClass())) { KR_CORE_ERROR("SpawnActor failed because {0} is not an actor class", Class->GetName()); return nullptr; }- Next, there is some checking of template classes which are used for CDOs (Class Default Objects) that we won't be discussing at this stage because we are not using them.
- Finally we check if the
ULevelis not collapsing or being torn down. If so, then no use of spawning theAActorand return nullptr.
- First we check if the specified