Unexplainable behavior from GetWorld()->SpawnActor

So far nobody on any Discord channels has had any answers to this issue, and it’s been really unproductive trying to Google something like this, so I’m just hoping someone might recognize these symptoms and have some advice here.

I’ve created a grenade actor that will be spawned via GetWorld()->SpawnActor. The actor has a ProjectileMovementComponent and a StaticMesh. The projectile movement component is set to use an initial speed/max speed of 1000.0, and bShouldBounce is set to true. Other than that, all settings are default.

The behavior I’ve observed is:

  • The actor spawns into the world and shows up in the actor list. However, instead of using the given location, it appears to travel off in some random X/Y/Z direction at a really high rate.
  • Along with this, it is invisible. I can never see the static mesh leave from any direction, and when selecting it from the actor list and focusing it, there is never anything there.
  • When pausing the editor, the actor continues to travel at the random rate/direction.
  • I have set a lifetime on the actor of 5 seconds, it seems to totally ignore this.

My code for the spawning process is as follows:



void ASurvivalCharacter::SpawnThrowable()
{ if (UThrowableItem* throwable = GetThrowable()) // returns the reference to the throwable item from the inventory
{
  [INDENT=2]if (throwable->throwableClass) // check that the weapon class is valid
{[/INDENT]
  [INDENT=3]FActorSpawnParameters spawnParams;
spawnParams.Owner = spawnParams.Instigator = this;
spawnParams.bNoFail = true;
spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;

FVector eyesLocation;
FRotator eyesRotation;

// load the controller location into the two vectors
GetController()->GetPlayerViewPoint(eyesLocation, eyesRotation);

// spawn grenade slightly in front of controller location so it won't collide with the player
eyesLocation = (eyesRotation.Vector() * 20.0f) + eyesLocation;

if (GetWorld()->SpawnActor<AThrowableWeapon>(throwable->throwableClass, FTransform(eyesRotation, eyesLocation), spawnParams))
{[/INDENT]
  [INDENT=4]MulticastPlayThrowableFX_Implementation(throwable->throwAnimation); // play the throw animation[/INDENT]
  [INDENT=3]}[/INDENT]
  [INDENT=2]}[/INDENT]
  }
 }


I’ve uploaded a short video of the actor list immediately after the code executes: https://i.imgur.com/lPRuIpw.mp4

I haven’t used the projectile movement component much, so hopefully this is just some dumb mistake I’m making with the spawn params or the setup of the movement. Any advice would be greatly appreciated.

I would start by putting a projectile directly into the world, right in front of me to see its behaviour.

What are you projectile component settings? Initial speed, collisions, velocity, …

Are it’s spawning location and direction right?

Solved it. Thankfully it was a stupid mistake.

I’m following a course and there’s two blueprints for weapons: the item you pick up from the world and the one that is used as the weapon. The pickup sets the class the weapon will be. I had mistakenly chosen the C++ class for the grenade versus the Blueprint of it, so it was spawning in the C++ base class into the world every time I threw a grenade.