Download

Trying to get class successfully :(

Hi!

I have this in the.h file:

TSubclassOf < AActor > tankClass;

and this in BeginPlay() (.cpp file)

tankClass = LoadClass(nullptr, TEXT(“Blueprint’/Game/TankBP.TankBP’”));

when i check tankClass it is always nullptr :frowning:

Blueprint’/Game/TankBP.TankBP’ <— this is the reference copied from editor

What i am doing wrong?

solved by replacing:

Blueprint’/Game/TankBP.TankBP

by:

/Game/TankBP.TankBP_C

W H Y ! ? ! ?

becuase “_C” is the class.

Isn’t it obvious?

This is a package:

/Game/TankBP.

This is a blueprint

/Game/TankBP.TankBP

And this is a class:

/Game/TankBP.TankBP_C

Use the first to do poackage things. The second to do Blueprint Things. But you need a class to Create real objects in game.

Its confusing in the editor. It wont show you the _C excepot when simulating. Turn your TSubclass into a UPROPERTY with a pulldown. THen look at what you get in code when you set it and ask it for what class it has…

1 Like

Hey! thank you very much for the expllanation. It is obvious once you know it because I was literally hours to figure it that needed add the _C when referencing classes.

Thanks again!