Spawning Blueprint Objects Problem

Hey guys,

I’m very new to Unreal. I followed the C++ FPS tutorial and have gotten to the end. I figured that in order to get a better understanding of things, I would try to simulate an explosion when the projectile hits something. I came up with the following code, using the already existent Blueprint that comes as an included asset:

void AFPSProjectile::OnHit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
	if (OtherActor && OtherActor != this && OtherComp)
	{
		OtherComp->AddImpulseAtLocation(ProjectileMovement->Velocity * 100.0f, Hit.ImpactPoint);

		/* now also create explosion on impact*/
		static ConstructorHelpers::FObjectFinder<UBlueprint> explosionBlueprint(TEXT("Blueprint'/Game/Blueprints/Blueprint_Effect_Explosion'"));

		if (explosionBlueprint.Object != NULL)
		{
			UClass* uclass = explosionBlueprint.Object->GeneratedClass;
			
			FActorSpawnParameters SpawnParameters;

			SpawnParameters.Owner = this;
			SpawnParameters.Instigator = Instigator;

			UWorld* const world = GetWorld();
			if (world)
			{
				FRotator const rotation = Hit.ImpactNormal.Rotation();
				AActor* actor = world->SpawnActor<AActor>(uclass, Hit.ImpactPoint, rotation, SpawnParameters);
			}
		}
	}
}

When I run it, nothing happens when the spheres hit geometry. The impulse does happen as usual, but not the actor spawn. To make things worse, have firing 5 or 6 projectiles, the editor crashes. I’m wondering if I’m doing something incredibly stupid here. Any help would be greatly appreciated!

The line

static ConstructorHelpers::FObjectFinder<UBlueprint> explosionBlueprint(TEXT("Blueprint'/Game/Blueprints/Blueprint_Effect_Explosion'"));

needs to be in the constructor of the class. You can create a pointer in the header:

TSubclassOf<class AActor> BallBlueprint;

and then put this into the constructor aswell:

explosionBP= (UClass*)explosionBlueprint.Object->GeneratedClass;

Then

AActor* actor = world->SpawnActor<AActor>(explosionBP , Hit.ImpactPoint, rotation, SpawnParameters);

Unfortunately my compiler complains: value of type UClass* cannot be assigned to type UBlueprint* . Is it a typo?

Also complains about the SpawnActor function not taking a UBlueprint*

Is it just a matter of casting to UClass* ?

I made a slight typo, the header should declare the blueprint a subclass of an actor. Updated the code.