Download

Spawn Actor Warning Spam

I’m currently creating a “chain” projectile that will spawn another projectile or explosion actor on impact before immediately destroying itself. Things are mostly working but a few things are off and these mass warnings are an obvious red flag that I can’t seem to get rid of because the engine doesn’t tell me where it occurred!

My projectiles are essentially just actors with a StaticMeshComponent and a ProjectileMovementComponent.

Every time I spawn new projectiles I get this warning:


LogUObjectBase: Warning: NULL object

Just to try to over explain WHEN the warning is showing:
Projectile1 Collision → Spawn Projectile2 → Projectile1 Destroys self → Warning

I’ve tried storing the spawned actor (“Projectile2”) as a UPROPERTY() in “Projectile1” because it could be an issue with garbage collection. No luck there.
I’ve also tried NOT destroying the “Projectile1” after spawning the new one (“Projectile2”) - just to see if I could get rid of the warning. This resulted in the warning showing up much less often (like ~50% of the spawns)

Here is my spawn projectile Code:


AGameProjectile* AGameMeshProjectileChain::SpawnProjectileChain(const FVector& Location, const FRotator& Rotation)
{
    AGameProjectile* SpawnedProjectile = nullptr;

    FActorSpawnParameters ProjectileSpawnParams;
    ProjectileSpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;

    // spawn projectile
    UWorld* World = GetWorld();
    if (World)
        SpawnedProjectile = World->SpawnActor<AGameProjectile>(ProjectileChainClass, Location, Rotation, ProjectileSpawnParams);

    if (SpawnedProjectile != nullptr)
    {
        // set projectile owner
        if (GetOwner() != nullptr)
            SpawnedProjectile->SetOwner(GetOwner());
        else
            SpawnedProjectile->SetOwner(this);
    }

    return SpawnedProjectile;
}

I’m not entirely sure what bit of code is relevant here because the warning doesn’t point me in a direction. This function produces a completely valid actor from what I can gather. I’ve narrowed it down as much as I have now using UE_LOGs all over the place. I would be more than happy to give you more to look at if this is unhelpful.

I’m fairly certain that it has something to do with the actor destroying itself immediately after spawning another - but keeping it alive only seems to lessen the warning spam and obviously isn’t practical. I’m praying you brilliant people will point out something I’m doing incorrectly!

I’m using the newest engine v 4.24.1

Figured it out! Just a follow up to help anyone who finds this in the future. I thought the warning was because of actor spawning or garbage collection but it was actually some code in my custom DestroyProjectile() function.

My projectiles had an optional particle system component that I destroyed when the projectile actor got destroyed. I was calling IsValidLowLevel() on the sometimes uninitialized component before destroying it. I initialized the component to nullptr in the constructor and added a nullptr check in the DestroyProjectile() function before calling IsValidLowLevel().


// destroy particle system
    if (ProjectileParticleSystemComponent != nullptr) // ADDING THIS GOT RID OF THE WARNING
    {
        if (ProjectileParticleSystemComponent->IsValidLowLevel())
        {
            ProjectileParticleSystemComponent->SetActive(false);
            ProjectileParticleSystemComponent->DestroyComponent();
        }
    }

Hope this helps someone!

You need to add break points to the code and see step by step when that log comes. It seems you are trying to access the projectile 1 even after its deleted, try de-registering it and then delete it.