I’ve been struggling with this bug for a few days now.
I’m just a begginer at programming have been following tutorials here and there.
I’m trying to spawn actors using the following code in cpp file (in BeginPlay, but have tried in Tick as well) :
Everytime I hit play, the window freezes and the editor crashes.
Since I use pointer checking, I guess I am not dereferencing null pointers.
I’ve had a look at similar issues, but without success so far.
Any idea of what is going on?
By doing GetClass, you are not really getting the class you want (you are getting blueprint generated class) To get the class that is referenced by the TSubclassOf, use Get() or simply dereference it. Ah, and there is really no need (rather discouraged) for using “this” keyword unless you need to use it.
Try doing something like this (I have used zero rotator/vector for test, but you can leave your transform):
UWorld* const world = GetWorld();
UClass* const actorClassToSpawn = ActorToSpawn.Get();
if (world && actorClassToSpawn)
{
AActor* const spawned = world->SpawnActor<AActor>(actorClassToSpawn, FVector::ZeroVector, FRotator::ZeroRotator);
if(spawned)
{
// yay
}
}
, I made the changes you mentioned. Indeed, I had the check wrong.
I’m making progress because, I can spawn basic actors thanks to your recommandations.
However, when I want to spawn custom actors from class ASparePart, the editor crashes again.
I had a similar issue 30 minutes ago. After several trials & errors, i figured out that the fact i was specifying the name of the actor to span in my FActorSpawnParameters was triggering a deep engine crash at the second spawn only. I’m running Unreal 5.1.