Try googling some tutorials on Object Oriented programming. In my experience a lot of newcomers don’t have this basic knowledge which underpins everything.Once you get the basics of OOP you won’t have any troubles accessing vars.

It’s not easy to sum up in a single post, but I’m bored so here goes…

Classes define a template, or blueprint, consisting of properties (variables) and methods (functions) which together makeup the members of the class. This template is used to produce objects through a process called instantiation (Spawn for actor type classes).

Are the real, tangible instances of a class. Individual instances of objects can hold different data. Instances of an Actor class can have different Location and Rotation values, for example.

The difference
Consider the class as an asset, and an object as a ‘living copy’ of that asset. Whereas the class defines variables and functions, it’s the object that actually holds the values of those variables and executes the functions. A single class can be used to produce many objects.

The pitfall
The biggest mistake when learning OOP is to think of your game world as a collection of classes. They are objects. The class defines their properties and behaviour. Your player, his weapon, that missile, the explosion, the score printed on the HUD… objects, whose type is the class that defines them.

When an object is created we need a way to address it, or reference it. The Spawn() function will create an actor in the world and return a reference to that actor, which you can store and use to access it.

References are not instances
A reference points to an object, but is not the object itself. The object exists in memory and you can have several references all pointing to the same object.

When actors are spawned a reference is also stored internally. Iterators such as AllActors, AllDynamicActors, etc are searching through lists of such references.

Types, Typecasting
(You know what, I’m really too tired to go into this one tonight, lol)

A reference that points to nothing. It’s sometimes important to check a reference is valid before using it, and you’ll see the pattern “if( reference != None )” repeated everywhere.

Garbage Collection
Objects live until there are no more references pointing to them. Lonely and dejected, they’re embraced by the garbage collector… which puts them out of their misery by destroying them. However, remember that the engine maintains internal references to actors, so an explicit call to Destroy() is necessary for the engine to ‘let go’ too.

Getting a reference
Most classes perform a specific role within a system. PlayerController’s role is to handle player control, Pawn’s role is to represent the player as a physical entity. Since their roles are deeply connected they both contain references to each other. This pattern is repeated throughout the codebase for things like HUD, PlayerInput, Weapon, etc.

So accessing the variables and functions of an object becomes a question of “who maintains the reference to that object?” For example, the PlayerController and Pawn have references to each other, but the PlayerController is the only one with a reference to the HUD. How to access the HUD from the pawn? Go via the playercontroller:

// Accessing our CustomHUD from CustomPawn.uc...

if( PlayerController(Controller) != None && CustomHUD(PlayerController(Controller).MyHUD) != None )
    CustomHUD(PlayerController(Controller).MyHUD).StaminaBar = 100;

Classes can extend other classes. The parent class is called the base or super, while the new class is the derived or sub class. When a class extends another class it inherits all the qualities of the base class. Thus a variable defined in the base (or deeper down the inheritance chain) is part of the new class.

If ClassSub extends ClassBase, then an object of ClassSub can be considered as type ClassBase as well as ClassSub. This is because ClassSub is a ClassBase. For example, Siamese extends Cat… Siamese is an object of type Siamese, but it is also an object of type Cat: Siamese is a Cat. However, a Cat object is not necessarily a Siamese object.

The small print
Classes are actually objects that can hold values and execute functions. But, don’t tell anyone I told you that because it’s very confusing