Unreal Engine Classes Within

The title has been deliberately written to match that of Final Fantasy: The Spirits Within. With that taken care of, let me focus on the Unreal Engine part. Within is a class specifier for Unreal Engine C++ UCLASS() macro. The official documentation is like so

Within=OuterClassNameObjects of this class cannot exist outside of an instance of an OuterClassName Object. This means that creating an Object of this class requires that an instance of OuterClassName is provided as its Outer Object.

A use case is

UCLASS(Within=STWeapon)
class SUNOVATECHZOMBIEKILL_API USTWeaponState : public UObject
{
 GENERATED_UCLASS_BODY()
 ...
}

where class ASTWeapon is defined like so

UCLASS()
class SUNOVATECHZOMBIEKILL_API ASTWeapon : public UObject
{
  GENERATED_UCLASS_BODY()

public:
 /**
   * @brief Getter for the Owner of this inventory
   */
 ASunovatechZombieKillPawn* GetSTOwner() const
 {
  return STOwner;
 }
  ...
}

Now the GetSTOwner() can be accessed via following code in USTWeaponState

GetOuterASTWeapon()->GetSTOwner();

Iterators : The proper way

यदा यदा हि धर्मस्य ग्लानिर्भवति भारत

धर्मसंस्थापनार्थाय सम्भवामि युगे युगे ॥7-8, Chapter 4॥

A shalok or verse, from Geeta, that is known to many Hindus, or the gist of which gets reflected in our actions (I am a Hindu) anyway, is the representation of iterative theme, of course, coupled with a right action mentioned above. The meaning implies that Shri Krishna takes birth in an epoch, time again, whenever there is rise of evil, to establish law and order.

Unreal Engine has a way of iterating over the C++ objects which has been used in hundreds of AAA games covering a stretch of couple of decades.

The iteration is done like so

for (TActorIterator<AActor> ActorItr(testWorld); ActorItr; ++ActorItr)
{
	// print name
	KR_INFO("Iterating over actor: {0}", (*ActorItr)->GetName());
}

The TActorIterator template is defined here. The pseudo code for iteration roughly is

  1. Initialize ActorList with the appropriate UObjects (of a world or editor relevant objects for instance) of cached objects.
  2. Appropriately define (overload) the increment (++) operator with desired class filters and appropriate checks

A fruitful thing is to think what remains constant and what doesn’t in this way of iteration, which in turn defines the concept of iteration.