SpawnActor causing crash, but there isn't any problem with the code. Possible bug?

So I am following this tutorial: BP Twin Stick Shooter: Building the Projectile & Weapon | 09 | v4.8 Tutorial Series | Unreal Engine - YouTube

but I am doing more things in C++. I have a character class, a weapon class, and a projectile class.

I have successfully spawned my weapon without a problem: Screenshot - 94f2a7748b2852e1f244bc1c6fbc573c - Gyazo

but when I go to spawn my bullet by shooting my gun, the game crashes. It specifically crashes on this line:

ATutorialProjectile* SpawnActor = GetWorld()->SpawnActor<ATutorialProjectile>(MyProjectile, MyArrow->GetComponentLocation(), MyArrow->GetComponentRotation());

The blueprint is set up like this:

    class ATutorialProjectile; // forward declaration, this is above the UCLASS()
    TSubclassOf<class ATutorialProjectile> MyProjectile;

//in constructor
	static ConstructorHelpers::FObjectFinder<UBlueprint> ProjectileBlueprint(TEXT("Blueprint'/Game/Blueprints/BP_Projectile.BP_Projectile'"));

	if (ProjectileBlueprint.Object)
		MyProjectile = (UClass*)ProjectileBlueprint.Object->GeneratedClass;

//in void Fire() function
	if (MyProjectile != nullptr)
		ATutorialProjectile* SpawnActor = GetWorld()->SpawnActor<ATutorialProjectile>(MyProjectile, MyArrow->GetComponentLocation(), MyArrow->GetComponentRotation());


I’ve already tested to see if it was maybe the MyArrow component that was crashing me, but it wasn’t. I replaced the FVector location and FRotator rotation with 0.0f, 0.0f, 0.0f just to see, and it still crashed. It’s 100% the MyProjectile object, but I don’t see what I’m doing wrong. I did the exact same thing for my Weapon in another class, and it works perfectly. I’ve also done this before without a problem. It’s almost like it just doesn’t like my blueprint for my projectile.

Is this some sort of bug? I used this method of spawning actors a ton of times before and not had problems. It’s like the engine selectively chooses when it wants to accept a blueprint.

ALSO, MyProjectile, my projectile blueprint, isn’t returning nullptr, so I honestly have no idea what is going on.

Hey Snowl0l-

More information is necessary to help investigate this issue. Can you provide the callstack and log files from the crash? If possible, please also include the full code for your projectile class to help me reproduce the issue on my machine.

Didn’t know you responded, sorry. I would’ve responded earlier, but I’m kinda glad I didn’t. It just started working, as I’m writing this. I didn’t change anything. It just worked. I can’t really explain it. I’m like 1000% positive there’s a bug somewhere here, I just can’t explain what it is. This has happened to me before, a long time ago, where the game would constantly crash because it wouldn’t accept my blueprint. It wouldn’t return null, but the actual

TSubclassOf —

would be corrupt and it would just crash over and over again. I don’t know why, but it’s something like that.

My projectile class was just a class extended from AActor with nothing added:

Even though I’m no longer having the issue, could you still look into it possibly being a bug? I think it has something to do with the path to the blueprint not being properly or something. This is the second time I’ve run into this, and I have a feeling I’ll run into it again.

I don’t exactly know what logs you want. These were taken from my /Project/Saved/Logs folder from last night when the issue was still occurring:

[2016.11.17-05.34.43:971][311]LogClass: Function CalculateHealth is new.


[2016.11.17-05.34.44:230][311]LogWindows:Error: === Critical error: ===
[2016.11.17-05.34.44:230][311]LogWindows:Error: Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x000000b0
[2016.11.17-05.34.44:230][311]LogWindows:Error: UE4Editor-Engine.dll
[2016.11.17-05.34.44:230][311]LogWindows:Error: UE4Editor-Engine.dll
[2016.11.17-05.34.44:230][311]LogWindows:Error: UE4Editor-ProjectPenguin-6639.dll

It just says Unhandled Exception.

If you need logs from elsewhere, or if you need the entire log, let me know.

always check if GetWorld() is valid.