How can I get a Blueprint Actor in C++?

Here is my scenario:

  1. [in VS]Derive a subclass called AStrikeZone from AActor, which basically contains a UBoxComponent as a trigger volume

  2. [in editor]Create several blueprint instances that derive from AStrikeZone in the editor

  3. [in editor]Adjust the blueprint zones in the editor

  4. [in edtior]Set the above zones to a player blueprint whose exposed C++ properties are declared like this:

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=blahblah)
    TSubclassOf BackCourt;
    Now in the blueprint’s default panel, I can set AStrikeZone blueprints to BackCourt property. The problem is, by using TSubclassOf<>, the reference ‘BackCourt’ has a type of UClass instead of AActor, and all the methods and properties defined on AStrikeZone become unavailable as the compiler throws this error:

    ‘getBoxExtent’ : is not a member of ‘UClass’
    Then I tried to expose the property as a raw pointer:

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=blahblah)
    AStrikeZone* BackCourt;
    Now in its blueprint defaults panel, I can see the instanced blueprints showed up in BackCourt’s dropdown menu, but they seems to be un-selectable(click them and nothing happened…)

Anyone pls shed some light onto this? Any help would be great!

Found answer in this post:

Updated: the answer in the above link is not sufficient
UClass::GetDefaultObjct() just creates an empty object, and ignores the objects created in editor.

TSubClassOf will allow you to select from a dropdown the classes that derive from the one you specify, but that is not an instance. That is usually used to set the class of an actor you are going to spawn in the world and you need to know what the uclass is. I’m not sure how to do that for instances, i tried TSubObject of an actor and it crashed.

I believe TSubobject<> is usually used with ActorComponents.

There are several predefined ‘singleton-like’ actor classes (like gamemode, gamestate, etc) whose references are kept/managed in UWorld and can be accessed using the GameplayStatistics helper methods. TSubclass is perfect for this kind of use as you can set your customized blueprint class to GameMode and then in the code get access to the instanced actor.

For runtime spawned actors, it’s also not a problem, as UWorld::SpawnActor<…>(…) always returns a pointer to the spawned actor.

The only trouble is to deal with editor-time created actors. To get access to them in native code, a general solution is to iteratively search all actors/objects by name. Besides that, I think it is also reasonable to make those actors register themselves to somewhere in their first Tick()

To do the dropdown of actor instances you just do:

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = GeomProcess)
AActor *    GeometryMesh;