This code has always worked, now in 4.9 it crashes. Calling spawn actor from blueprint node inside a blueprint lib function. I don’t see a world context pin or anything. Any suggestions?
UWorld* UEngine::GetWorldFromContextObject(const UObject* Object, const bool bChecked) const
{
if (!bChecked && Object == NULL)
{
return NULL;
}
// Object is NULL, crashes here…
check(Object);
bool bSupported = true;
UWorld* World = (bChecked ? Object->GetWorldChecked(bSupported) : Object->GetWorld());
return (bSupported ? World : GWorld);
}
AActor* UGameplayStatics::BeginDeferredActorSpawnFromClass(UObject* WorldContextObject, TSubclassOf ActorClass, const FTransform& SpawnTransform, ESpawnActorCollisionHandlingMethod CollisionHandlingMethod, AActor* Owner)
{
AActor* NewActor = NULL;
UClass* Class = *ActorClass;
if (Class != NULL)
{
// If the WorldContextObject is a Pawn we will use that as the instigator.
// Otherwise if the WorldContextObject is an Actor we will share its instigator.
// If the value is set via the exposed parameter on SpawnNode it will be overwritten anyways, so this is safe to specify here
APawn* AutoInstigator = Cast<APawn>(WorldContextObject);
if (AutoInstigator == nullptr)
{
AActor* ContextActor = Cast<AActor>(WorldContextObject);
if (ContextActor)
{
AutoInstigator = ContextActor->Instigator;
}
}
UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject);