What are classes derived from parent classes really

Just a quick question.
Are classes that we make actual subclases of the parent class and there for the classes that we make inherit from the parent class everything since it’s really a subclass in technical terms.

So any AActor class that get’s created is really a subclass of the main actor class ?
Why did I ask this. Take for example TSubclassOf so were really mentioning sub classes ? The reason I asked this is can I call on a parent class with TSubclass, for example, I can’t right ?

If I do this TSubclassOf<“AActor”> I just made a range of classes to call on belonging to the AActor class, I’m not really calling on the parent class . Is the TSubclassOf<> recomended into calling parent classes to get data from them directly, functions, variables and so on. Why is it called a subclass.

Your wording confuses me a bit but I’ll try to answer.

First, the AActor class not an Actor class, it is THE Actor class. I believe it inherits from (a child of) UObject.

When you say

So any AActor class that get’s created is really a subclass of the main actor class ?

It depends on what you mean by ‘created’.

When you create a new Actor class (either C++ or Blueprint) from within the Editor, you automatically create a subclass of the Actor class. In Blueprint, it tells you the parent class in the top right corner. In C++, near the top you will see something like class AChildClass : public AActor.

When you spawn an Actor (using the SpawnActor node), you are not creating a subclass of the Actor class, you are creating an instance (aka an object) of the Actor class.

If you use TSubclassOf or any form of cast to AActor, you are simply saying ‘an AActor or any subclass of’.
For example, you can have an AActor* that points to an APawn object (since APawn is a subclass of AActor).

As for calling something directly on the parent class, I don’t see why you would ever want to do that. If you want something from the parent class, it will still be obtainable from the subclass. The only time this won’t be the case is when using virtual/override methods, but even then, just don’t override them then.

Finally, TSubclassOf has nothing to do with calling. It’s basically a way of selecting which class to use when spawning a new object. It stores a reference to a class; not an object like everything else.

Let’s say you had a Weapon class, with two subclasses, Rifle and Pistol.
In your Character, you will have a TSubclassOf<AWeapon> WeaponToSpawn variable. In BeginPlay, you will then use SpawnActor method to spawn in the WeaponToSpawn.
In the Editor, you can then choose which type of Weapon to use for WeaponToSpawn. Rifle or Pistol? Whichever you choose is the one the Character will spawn with.

1 Like

I will answer you tomorrow dynamiquel, thansk for the reply the coffee kept me up all night, I have to go to bed it’s morning , but thanks and I will see when I wake up, I want to get a hold of a class that does not get created based on it’s parent, so this is why I’m asking if this can be done.

So the Tsubclass I know how this function, I have used it before, to spawn other actors to bring in actors so I can attach them to socket and so on.

When you create a new Actor class (either C++ or Blueprint) from within the Editor, you automatically create a subclass of the Actor class. In Blueprint, it tells you the parent class in the top right corner. In C++, near the top you will see something like class AChildClass : public AActor .

So it’s a subclass, this is what I wanted to know, so Myactor2 class is a subclass of the main Actor class.

When you spawn an Actor (using the SpawnActor node), you are not creating a subclass of the Actor class, you are creating an instance (aka an object) of the Actor class.
When I am not creating a class you mean and just spawning ? then yes I agree.

So now we got the ActorClass and ALandscape is part of the actor class.
Now strange tho it is under the actor class and the actor class should be it’s parent meaning Actor.h
the Landscape class all tho part of the Actor root folder class it’s not part of the Actor.h but Landscape.h

So this landscape class is a class within the actor class but sort of it’s own parent.

So when trying to create a child class, that is derived class from the Landscape class , based on the Landscape class right , well it cannot be created and throws errors, I made another thread about this. This is not the place.

So since I can’t create this class that is a child of the Landscape class then I want to go around here and use Tsubclassof to get access to Landscape.h.
But strange enough parent class Landscape.h is it’s self under the actor class, how come ?

So the question is anyway, can I use the Tsubclass on this parentclass, and get data from this parent class by refrencing the class with Tsubclass .

is the TsubclassOf only suppose to work with subcasses ? can we include parent class and is this recomanded to use it like this, to get all of the class variables, functions and data thru this type of refrencing, maybe I don’t know I may get some problems later for doing this. Can I even get access to landscape class I hear it’s minimal api but others got access to it’s functions, I have seen it, there are books and so on, but maybe that was a long time ago and it’s no longer possible.

So this is my other thread.
How to add a class derived from ALandScape class - Development Discussion / C++ Programming - Unreal Engine Forums

This is why I created this one, to find another way to that class since that solution is not working, I think you get the idea now.

Is it really recomended to use this TsubclassOf to get in all the functions and variables of the other class that is tied to the module I want stuff from, I haven’t tried but I could, would it even work, will it refrence the main Landscape.h class, what is this class, is it a parent class, or it a smaller parent that belongs to the actor class, if I somehow manage it to work would I not get surprises in the future.

Thank you, if you or anyone can help me.

TSubclass<AActor> will work with Actors and any subclass, such as APawn, ALandscape (anything beginning with an A). However it will not work with any of the Actor’s parents, such as UObject.

Landscape.h isn’t really a class, it’s just a header file (which usually includes a class but can literally include anything). When talking about classes, it’s the actual class name you care about, in this case, ALandscape.

You should be able to spawn an ALandscape using TSubclass<AActor>. But I don’t think you’ll be able to do anything with it since it does say the methods cannot be called at runtime. It will yield the same results as Cast<ALandscape>(AbstractActor).

I can’t really tell if it’s an actor class or a uclass.

This is the derived child class I created from Alandscape parent class, since is ALand maybe it’s parented further to the main actor class. So I created it but does not compile, I may have found a fix for it, but if I can use TsubclassOf, i’ll go with this too.


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

include “CoreMinimal.h”
include “Landscape.h”
include “MyLand.generated.h”

class MYPROJECT211_API AMyLand : public ALandscapeProxy


So the main include leads to Lanscape.h that is the parent class.
But the child class as you can see has a strange format.

class MYPROJECT211_API AMyLand : public ALandscapeProxy
This makes it also an actor class ?

You see " public ALandscapeProxy" AMyLand.

So the main Landscape.h is the parent of this class but Landscape.h is parented further to the actor class, or is it independent ? And why does it create my child class as an actor class parented to Landscape.h

So this module landscape is part of the actor class or is it independent.
So Landscape.h is a smaller parent class ? and I may or may not be able to tap inside of this class with Tsubclass of ?

Again. Landscape.h IS NOT a class. It’s just a file that contains classes. Under normal circumstances, it usually includes only one class. But in Unreal, it can contain several classes. In this case, the Landscape.h file contains ALandscape and ALandscapeProxy.

The parent class is ALandscapeProxy (you can see that since it’s after the : ).
And yea, it is a subclass of the Actor class. There’s two ways to check this.

  1. It begins with an A. Unreal uses a prefix system so it’s easier to tell what it what. If a class begins with an A, then it is a subclass of Actor.
  2. You can just middle click or control+left click where it says ALandscapeProxy, this will take you to it’s class declaration location. Here, you can see who the parent of ALandscapeProxy is, and then do the same for that and so on until you find the parent you are looking for.

Just to add my 2 cents:

Screen Shot 2022-01-05 at 11.44.58 AM

The class I showed you above that is created with the .h file is made by doing this

So I clicked create new class
Clicked show all classes.
I went to choose a parent class and chose the Landscape class as seen in the image, clicked the next button and chose a name for the class MyLand, is the name I typed in, but upon creation it generated the files and the header file of it you can sea in the above post, but did not want to compile at all.
As you can see the file it generated is based on an actor class but it included by it’s self #include “Landscape.h”

and public ALandscapeProxy
So this class is suppose to be parented to the Landscape main class, but it is parented to the actor class with the landscape class elements.
It’s a mixed child class, what is it.

yeah pezzotti, It may be an actor class and Landscape class is a smaller parent making the landscape module dependant on the actor ?

Why does it not compile and find the module if the module is part of Aactor class.
In stead it does not and refuses to compile by throwing a bunch of external errors external not found (the module not found I bet it wants to say)

This can only mean that they moved the landscape module elsewhere from the actor class ? there for it does not compile and landscape now has become a main parent class maybe ?

Subclasses can have different dependencies from their parent class. I haven’t used Landscape before but it’s entirely possible that to use them within C++, they require you to enable an additional module in your project settings (.uproject file).

I tried that dynamic, I included the modules in my build.cs file like some told me, but I did not manage to get it to compile because it did not find the module even with the specified modules in the build.cs

So now there may be one thing I can do maybe it will fix it that I will try later, and if that does not work I will try with Tsubclass to call on the Landscape class and see what I can get like this if of course Landscape is a subclass of the actor class and not a main parent, like you said, main parent classes can’t be called like this.

Sure, you can try, but I don’t know what you mean by ‘main parent class’. Do you just mean it isn’t a subclass of anything?

Well if the module has been moved (reason for it’s fail to compile) it must mean that landscape has become the main class since it’s now independent from the actor class maybe, I don’t know.

It’s the head parent class maybe.

Why does it need a include to landscape.h if the actorclass has all the module.
The parent class Actor class parent should provide everything, yet it does not and everything is in landscape class not in the main actor class that is the parent of all the actor classes

Why does it need
#include Landscape.h|

if everything it inherits comes from actor class parent.
Makes no sense. So it’s not just a regular subclass maybe or it’s not part at all of the actor class and it has been moved, since the module cannot be found in the actor class, it gives errors that it cannot find it, if it was part of the actor class the module should be there.

So the only explanation is that they moved the module from the actor class and landscape may be a parent class and they might of created it after the actor class to resemble an actor class but no longer of the actor class, like they used the same type of actor class code to create a new module, but left everything in the dark because they don’t want people getting api control over it ?

So no documentation, where is the new module etc :slight_smile:

No. Just because its module has been moved does not mean it is independent. A module can depend on other modules.
Also the concept of main class should be forgotten. Why? Every class is a subclass of the object class so technically it’s still a subclass. Also, the chances that you will be dealing with a class that isn’t inherited from something is very low (especially in Unreal).

The Actor class knows nothing about its subclasses. Inheritance is a one-way relationship. The subclasses know about the parent but not the other way round.

Sorry for sounding rude here but I’m going to be blunt. You should forget everything you already know about object-oriented programming and learn it from scratch. You have some misconceptions about it. If you think learning C++ again is too boring, then try learning C# (it’s an extremely useful language anyways), and learn it properly. No shortcuts. After you understand the basics of C#, that knowledge is easily transferrable to C++.

it’s okay Dynamiquel, I will learn more about it, and will soon go back about learning object oriented C++ programming to form a better opinion

It’s just that I think that they may have created a new class for the module since the module is no longer part of the AActor class. There is no reasons to throw those errors if it’s part of the Actor class.

Just looked more into this since I’m on my computer now. ALandscapeProxy requires LandscapeProxy.h. I am unsure why you are including the Landscape.h file in your MyLand.h file.

I am unsure whether the Landscape module is enabled by default. Let’s say hypothetically it wasn’t, then there is a reason.
When you use ALandscapeProxy, it gets info from LandscapeProxy.h and Actor.h. Actor.h is already part of the build so there is no issue there. Landscape.h is not part of the build and so it throws an error (it may sound dumb but the compiler doesn’t know anything about LandscapeProxy.h - your IDE might but that’s not what matters).

Because it’s how it generates the class, I’m not including anything, everything you see is included after the finishing of the class creation, I did not add any code.
It adds the code by it’s self but fails to compile.
All that you see is generated by the class when you hit create class.

This is it’s code by default. Seems the lanscape child class uses the proxy version.

Try replacing Landscape.h with LandscapeProxy.h and compile. But then again, if the engine is doing it, then there must be a reason that I don’t know of (it’s definitely not conventional).

yeah I tried similar, where you have class
MYPROJECT211_API AMyLand : public ALandscapeProxy
I did
class MYPROJECT211_API AMyLand : public ALandscape

but to no avail.