Download

Should a C++ actor have a corresponding BP derived from it?

As I’m diving deeper into Unreal C++ I start to have some problems make some trivial tasks.
A C++ Actor cannot be directly edited in the editor like a BP does (am I wrong on this?).
So, I’ve been creating BP actors derived from my C++ classes so I can edited them and those are the actors I use in my maps ( to set the Static Mesh for instance).

This brings me a problem,. If I’m using BP actors, how can spawn one of those actors from C++ as C++ doesn’t know about BP?

Edit:
I know I can do this:

In my character c++:
UPROPERTY(EditAnywhere, BlueprintReadOnly) TSubclassOf<class CActorToSpawn > ActorToSpawn;

And then set this in the character BP and then spawn ActorToSpawn from C++.
But is there another way? What if there are 10 different actors to spawn?

From my own projects, I only create actors in c++ and dont use blueprints (yet). You can drag the c++ icons into the editor, and if the UPROPERTY() is set correctly on any actor variables, you can edit the values.

You have to be very careful with this to update the editor actor every time you change the c++ because HotReload doesnt really work but there is a right click menu option to do this.

I actually find this much easier during development, than mess with blueprints as well, because when you update the c++, you still get the same problems, and then have another layer to mess with

When things are finalized, its maybe better then to use Blueprint derivations, but you will have to create a factory object or suchlike, and grab all the blueprints on level/game load using constructor helpers, and save a reference to them to be recalled later on spawn

How do you set static mesh assets? (and other assets)
Do you hardcode the asset path in c++?

Edit: having a BP for the C++ actors is also great for quick testing new functionalities.

I built global persistent preloaders that grabs all the asset references when the game instance is constructed, mesh, audio, materials etc on game load, then I assign them dynamically on construction of the actor. It works…

What do you mean by 10 different actors? 10 different Blueprints derived from your base class?

TSubClassOf is just ensuring that whatever the variable accepts needs to be derived from this class. You can use TSubclassOf<AActor> and any type of Blueprint that is derived from Actor will be valid.

You probably don’t want to make it as generic as Actor class but instead ensure that it is of the type of C++ class you created. Depends on what the pointer is used for.