Error Spawning Actor With Static Mesh In 4.9.1

I just updated my project to 4.9.1 and came across an issue spawning actors. I spent some time boiling the problem down, and this is how I am consistently reproducing it:

I create a Blueprint that inherits from Pawn, and call it TestPawn. I create an event handler for the ‘S’ Key, and when it is pressed, I spawn the actor in the StarterMap at the default MakeTransform location, and print a message if the SpawnActorFromClass returns an invalid result. It works fine.

I then open the TestPawn blueprint and add a StaticMesh scene component to the default root component. I set the StaticMesh to a Shape_Sphere, compile the blueprint, and save everything. When I run again and type ‘S’, the actor spawn fails and prints the error message.

Can this be reproduced and verified whether this is a bug? I didn’t have this issue in 4.8, it just started returning null when trying to spawn an actor in 4.9.

Hi Embeddetech,

Does this occur in a clean, blank project with no additional content or is it limited to one project? What specific steps are you taking that reproduce this on your end?

Hi ,
Yes, I initially simplified it in my working project, but then reproduced it in a fresh project in both 4.9.1 and 4.8.3. The procedure I used is as follows:

  • Launch the Editor in the appropriate version
  • Create a new Third Person Blueprint project
  • Create a new blueprint based on Pawn, and call it “TestPawn”
  • Open the TestPawn blueprint and add a StaticMesh component to the default scene component
  • Change the static mesh’s mesh to Shape_Sphere
  • Compile and save the blueprint. Should look like the attached image.

  • Open the level blueprint
  • Add an event handler for the ‘S’ key, use it to SpawnActorFromClass, select the TestPawn class, check to see if the result is valid, and if it is not valid, print “Spawn Error”. Example image below.

  • In 4.9.1, when you run the game and press “s”, the spawned actor returns invalid. If you remove the static mesh component, it will spawn successfully. If you do either in 4.8.3, it will spawn successfully.

Hi Embeddetech,

Unfortunately I haven’t been able to reproduce this on my end. Do you have a project I can take a look at that this is occurring in?

Hi ,
If you run this in 4.9.1, and press the ‘s’ key you should be able to see a “Spawn Error” message printed. And then if you delete the static mesh component from Test Actor and rerun you should see that it doesn’t print the error message. Let me know if you can’t reproduce.

Thanks!

I looked into this and found what you were talking about. I did some digging and have found that this is actually intended functionality. Most objects with collision will return a warning like this when they are spawning in a location that has collision already (for instance, other objects). You are getting a not valid check because the spawn actor you are using is using the default collision handling override, which will not spawn and return not valid if there are collision objects in the same location. Set the collision handling override to “Try to Adjust Location, But Always Spawn” and see if you still get the error you were seeing.

Thanks ! That fixed my issue. I was spawning actors from C++ classes, and was just using GWorld->SpawnActor(UClass * pClass). This didn’t cause any issues in 4.8 and earlier, but when I upgraded to 4.9 it started returning null and causing me issues. I used the code below and it successfully spawned. Thanks for the help!

		FActorSpawnParameters SpawnParms = FActorSpawnParameters();
		SpawnParms.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
		FVector Location = FVector();
		FRotator Orientation = FRotator();
		AActor * pSpawnedActor = GWorld->SpawnActor(pClass, &Location, &Orientation, SpawnParms);

Hi Embeddetech,

I’m happy to hear this is no longer occurring for you. I will mark this as answered for tracking purposes.

Yeah! I figured that out exactly before meeting this solution:))) But another approach is directly inside spawning actor set spawnCondition enum parameter in constructor like this:

SpawnCollisionHandlingMethod = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;