Unable to pawn Blueprint form C++

Hey mates. Me Again.

I am unable to spawn Blueprint (or even meshes like a simple box ) for some reason. I really digged around quite a bit and I am sure that it is something that is very simple an small escaping me. So decided ask here.

  • The blueprint is just the copy of the lamb blueprint in SampleContent. Just renamed it to Urgan.
  • It compiles just fine. The light also turns off/on. Just there is no Blueprint spawning.

By the way I am able to use ObjectInitiailzer to create things an attach them as components and do things with them.

Here is the code:

.h


	


public:


void Spawningu();

UPROPERTY(EditAnywhere, Category = Spawning)
TSubclassOf<class UBlueprint> MyBlueprinten;


// I am also turning on/off a light I initilaize. No need to wonder on. It works just fine.


UFUNCTION(BluePrintCallable, Category = Properties)
void TurnOnDaLight(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);



.cpp




ASaiyan::ASaiyan(const FObjectInitializer& ObjectInitializer)  : Super(ObjectInitializer)

{


 /// there is some stuff here


	static ConstructorHelpers::FObjectFinder<UBlueprint> SurpriseBlueprinten(TEXT("Blueprint'/Game/Urgan.Urgan'"));

	if (SurpriseBlueprinten.Object != NULL)
	
	
	{
		MyBlueprinten = (UClass*)SurpriseBlueprinten.Object->GeneratedClass;

	}


}



/// Turning on/off light at the same time I spawn the blueprint.

void ASaiyan::TurnOnDaLight(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)

{


	if (OtherActor && (OtherActor != this) && OtherComp)
	{
		if (MeinLight != NULL )
		{
			MeinLight->ToggleVisibility();
			Spawningu();
		}

	}

}



void ASaiyan::Spawningu()

{

	if (MyBlueprinten != NULL)
	{

		UWorld* const World = GetWorld();
		if (World)
		{

			UBlueprint* const SpawnedThing = GetWorld()->SpawnActor<UBlueprint>(MyBlueprinten, FVector(-400.0f, 0.f, 192.0f), FRotator(0.f, 0.f, 0.f), FActorSpawnParameters());

		}
	}

}



Thanks mates.

Hello TAN.

I do something similar, not exactly as what you are doing, but it may help. I have a manager that is responsible for spawning various actors within the scene. The manager makes use of FStreamableManager to dynamically load assets. The streamable manager is kept in my GameInstance:



UCLASS()
class MYAPP_API UMyGameInstance : public UGameInstance
{
    GENERATED_BODY()

public:
	:
	:
	FStreamableManager AssetLoader;
}


Which Actors are to be spawned by the Manager are stored in an array of TAssetSubclassOf:



UCLASS()
class MYAPP_API AMyManager : public AActor
{
	GENERATED_BODY()

public:
	:
	:

protected:

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "WaveData")
    TArray<TAssetSubclassOf<AMyPawn>> WaveData;
};


Because I keep other information per actor type, such as the number allowed at one time, and different property characteristics etc., the AMyPawn class type is used to hold the needed information, including the actual model.

Regardless of how it’s implement though, the manager needs to load the array of TAssetSubclassOf using the streamable manager:



void AMyManager::SetupWave()
{
    UMyGameInstance* gameInstance = (UMyGameInstance*)(GetWorld()->GetGameInstance());
    int32 waveCount = WaveData.Num();

    for (int32 x = 0; x < waveCount; x++)
    {
        if (WaveData[x].IsPending())
        {
            gameInstance->AssetLoader.SimpleAsyncLoad(WaveData[x].ToStringReference());
        }
        else
        {
            // this is done to reset an already loaded wave
            AMyPawn* pawn = WaveData[x].Get()->GetDefaultObject<AMyPawn>();
            pawn->SetupWave();
        }
    }
}


Then during the Tick event in the manager I check to see if it’s time to spawn an actor, and if so the following function is called:



bool AMyManager::UpdateWave()
{
    int p = FMath::RandRange(0, WaveData.Num() - 1);

    if (WaveData[p].IsValid())
    {
        FVector spawnLocation = FVector(0.0f, 0.0f, 0.0f);
        FRotator spawnRotation = FRotator::ZeroRotator;

        AMyPawn* pawn = GetWorld()->SpawnActor<AMyPawn>(WaveData[p].Get(), spawnLocation, spawnRotation);

        if (actor != nullptr)
        {
            spawnedPawns.Add(pawn);
            return true;
        }

    return false;
}