Object is not packaged error randomly occurs

I’m getting an object is not packaged error (ProjectileMovementComponent) that occurs when I try to spawn an actor with a projectile movement component (which causes the editor to crash). For some reason, this only occurs a small fraction of the time when I run the editor by opening my uproject file). It doesn’t occur when I run the editor through the debugger on Visual Studio. Rebuilding my solution only sometimes fixes the issue. Usually, I have to also launch the editor through the Visual Studio debugger. Only then does the error stop showing up when I launch through my uproject file (sometimes I have to do this repeatedly). I think it may be related to hot reloading or blueprint compilation, but I can’t seem to find a pattern. Most of the time, hot reloading and compilation works perfectly fine. Any ideas as to what’s causing this?

Hello,

  • How are you spawning your actor?
  • If you are getting a crash, please cause it again and provide the logs from your project’s Saved->Logs folder as well as your Machine ID from the crash reporter window. Please ensure to hit Send & Close on the CR window.
  • Have you been able to reproduce this issue in a clean project?
  • If so, please provide a detailed list of repro steps.

Hi,
I’m spawning my actor through c++. Here’s a code snippet:

FActorSpawnParameters SpawnParameters;
SpawnParameters.Instigator = Cast<APawn>(GetOwner());
AActor* Projectile = GetWorld()->SpawnActor<AActor>(MainProjectileClass, GetOwner()->GetActorLocation(), ShotDirection, SpawnParameters);
UProjectileMovementComponent* ProjectileMovementComponent = Cast<UProjectileMovementComponent>(NewObject<UActorComponent>(Projectile, UProjectileMovementComponent::StaticClass()));
ProjectileMovementComponent->ProjectileGravityScale = MainGravityScale;
ProjectileMovementComponent->RegisterComponent();
ProjectileMovementComponent->SetVelocityInLocalSpace(FVector(FMath::Min(HoldTime * MainProjectileSpeedMultiplier + MainProjectileSpeedMin, MainProjectileSpeedMax), 0.f, 0.f));

The crash randomly occurs when I play in editor and hit the action that spawns this actor. Unfortunately, I’m unable to reproduce the crash consistently. Sometimes, simply restarting the editor fixes the issue, so I have no clue what the exact steps are to recreate the crash. I have yet to come across the issue again, but once I do, I’ll post the log.

Meanwhile, what exactly does “object is not packaged” mean for a UProjectileMovementComponent? I’m not changing the code for the projectile movement component, so it’s not like it needs to get rebuilt and repackaged.

Found the issue. It wasn’t due to my projectile movement component, but rather my actor not spawning (so the object not being packaged was my actor). The randomness of the crash was caused by initializing the spawn rotation with FRotator(), thinking this constructor would return an FRotator with 0 values for pitch, yaw, and roll. Instead, it sometimes returns a rotator with NaN values, so my actor couldn’t spawn due to an invalid transform. Lesson learned. Always check if actor references are valid before adding components and manually initialize FRotators!