Add Impulse to spawned actor class from array

Hey everyone!

So inside of the Level Blueprint I’m using an array of actor classes and feeding that into a spawn actor. The idea is to pick a random actor, give it a random position within a set volume as well as a random rotation and scale. Then after the actor is spawned, give it a random Impulse (or Linear Velocity) to get the things to move. Gravity is currently set very low so everything floats.

Problem is… AddImpulse and SetPhysicsLinearVelocity both require a Primitive Component target which the Spawn Actor does not give. If I disconnect the Class array and set the actor manually (to a Cube in this case) then Unreal automatically converts the target to a Static Mesh and then to a Primitive Component.

But whenever the array is plugged back in, the target no longer carries over.

Only way I could think of to get this to work would be to add a GetRootComponent, plug it into a Cast To PrimitiveComponent and then do AddImpulse but the Cast continually fails. And I’m not even sure that’s the best way to do it, TBH.

Anyone have any ideas on how to get the PrimitiveComponent of a randomly spawned Actor class?

You can select the first found primitive component like this, cool.

1 Like

That did it! Absolutely fantastic. Thank you so much. Just for my understanding, since the actor blueprints did not contain a primitive component in them (they’re all just static meshes) does this method create a primitive component and then apply the impulse to it as if the static mesh was a child of the primitive component?

Either way, works like a charm. Thank you.

Oh yes you are correct this should include a validity check as the length could return 0 if there are no primitive components. You could create a primitive component but generally speaking Actors you want to perform this operation on will more than likely have a physical presence in your level already.