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!