Hey, i’m having some trouble spawning a blueprint from my C++ code and would appreciate some help with it.
This is the base C++ class of the blueprint i wish to spawn. I have created a blueprint that inherits from this class.
UCLASS(Blueprintable)
class HOMEINVASION_API UMurdererWaypointManager : public UObject
{
GENERATED_BODY()
UMurdererWaypointManager(const FObjectInitializer& ObjectInitializer);
public:
/** Find as all the waypoints in the current level. */
UFUNCTION(BlueprintCallable, Category = "Waypoint Functions")
void FindWaypoints();
}
But i have gotten stuck at this next part, in my GameMode i try to spawn the blueprint but cannot figure out how i should do this. I can spawn the class just fine if i just spawn the C++ version of the class using this.
WaypointManager = NewNamedObject<UMurdererWaypointManager>(this, "WaypointManager");
I tried using this to spawn the blueprint, but it did not work. (I check if the WaypointManager is valid)
In Gamemode.h
UMurdererWaypointManager* WaypointManager;
TSubclassOf<class UMurdererWaypointManager> WaypointManagerClass;
In Gamemode.cpp
static ConstructorHelpers::FObjectFinder<UBlueprint> WaypointManagerBP(TEXT("/Game/MurdererAI/AI_Blueprints/BP_MurdererWaypointManager"));
if (WaypointManagerBP.Object)
{
WaypointManagerClass = (UClass*)WaypointManagerBP.Object->GeneratedClass;
}
if (GetWorld())
{
GetWorld()->SpawnActor<UMurdererWaypointManager>(WaypointManagerClass, FVector::ZeroVector, FRotator::ZeroRotator);
}
Would be great if someone could help me out by telling me how you go about spawning blueprints that inherit from UObject in c++.