Skip to content

Karma Actor

Ravi Mohan edited this page May 30, 2023 · 5 revisions

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.

  1. Fist the following series of checks are performed:
    1. First we check if the specified Class object is not null (see the wiki page). The UClass object basically tells UObjectAllocator how much memory is to be allocated in the pool and aligned to what boundary. Also UClass is the specification of the type of UObject being spawned.
    2. Then we verify that the object that we are going to spawn is some child class of type AActor. Function IsChildOf basically 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;
    }
    
    1. 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.
    2. Finally we check if the ULevel is not collapsing or being torn down. If so, then no use of spawning the AActor and return nullptr.

Clone this wiki locally