Download

Instance of a class that inherits from class that inherits from AActor?

Hi,

I am new to unreal. I would like to know how to have an instance of my class in my level. I have a class that inherits from a class that inherits from Actor.

class B : public AActor

class A : public B

How can i get an instance of class A in my level?

I know how to get an instance of class B in my level. I just drag and drop from the content browser to my level in the unreal editor then attach a shape so I can see it.

How do I do this for class A?

Blueprints will appear in the content folder.
C++ actors do not.
To get an instance of class A in your level, you could add it via the level editor or create a Blueprint that uses class A as its base class, then drag that from the content folder.

Any changes you do to a Blueprint that uses class B as its parent will not affect the C++ of class A.
i.e. You create a Blueprint called BP_B and add a static mesh of a cube.
Any Blueprint or instance of class A will not have that static mesh.

If you want class B to affect class A, you will need to make those changes in C++ as normal.

There are some decent examples and tutorials floating around, both on this site and YouTube.
Hopefully they will give you some more insight then I have :slight_smile:

I was kinda hoping to do everything using Visual Studio and C++.

Its odd that you can only inherit your class from AActor directly and not inherit from a class that inherits from AActor!

Blueprint changes won’t.
C++ changes will.

Think of the Blueprinted version of B as another child - C.
Since you’re going B => C, it can’t affect A, which is B => A.
You would have to make A a child Blueprint of C for it to work.

Sure you can inherit from a class that inherits from AActor. Why shouldn’t that be possible?
It’s also possible to do everything in C++, since Blueprints are only ChildClasses of the C++ Classes.
But it’s not really recommended. Blueprints are there for a reason and they help debugging and creating
non logical stuff pretty fast. Adding a new Mesh to your Actor? Way easier in the Blueprint Child instead of
loading it in C++ and arranging it with numbers.

You can spawn Actors with the “SpawnActorsFromClass” Node in BP or with the equivalent code in C++.

Ok. Thanks for the explanation.

I will explain what i am trying to do so we are clear that i am new to unreal :slight_smile:

I am making a mining game. I have “Worker” and “Task” base classes. They both inherit from “AActor”.
“Task” provides some basic task functionality like starting,stopping, resuming and suspending a task.
“Worker” does something similar, keeps a list of tasks, current task, switches task based on signal etc
I then create class “Excavator” that inherits from “Worker” and also adds extra functionality like states, fuel, bucket capacity etc
I also create class “ExcavateSoil” that inherits from “Task” and adds extra functionality to command a Excavator to excavate soil :slight_smile:

So, after i had coded all that in Visual Studio i found i couldn’t see my “Excavator” and “ExcavateSoil” classes in the editor “Content Browser -> C++ Classes -> Mining”. But i could see my base classes “Worker” and “Task” there. Presumably because they inherit from AActor directly? While “Excavator” and “ExcavateSoil” are further down the inheritance tree?

If i could see my “Excavator” and “ExcavateSoil” classes in the editor i could just drag and drop them into my level and attach a shape.

You should check out the “UCLASS” parameters. There are some that control if the class can be spawned in the Level or if you are allowed to make a Blueprint out of them.

While you can drag and drop a C++ Class directly into the scene, you should also consider making a last Blueprint Child of your C++ class. It makes it easier to Edit base values etc
and you can definitely drag and drop that one into the scene.

But yeah, your C++ classes should show up in the folders. I just double checked and i can see mine, even if they inherit from something else than directly from AActor.

Figured out what was doing wrong!

I was not choosing the parent class in the editor. I was selecting “None” then in visual studio adding the code to inherit. So no wonder my classes weren’t showing up in the editor.
I worked out that i could select the “show all classes” checkbox and then search for my “Task” or “Worker” classes.

Thanks for the help and patience, i’m sure i will be back with another noobie question :slight_smile: