Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

alt text

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.

alt text

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

alt text

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.

alt text

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

Product Version: UE 4.15 Preview
more ▼

asked Feb 08 '17 at 08:47 PM in Blueprint Scripting

avatar image

48 5 5 10

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

alt text

getimpulsefix.jpg (42.9 kB)
more ▼

answered Feb 09 '17 at 07:40 AM

avatar image

1k 37 12 38

avatar image joelgerlach Feb 09 '17 at 10:11 PM

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.

avatar image MonsOlympus Feb 09 '17 at 11:08 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question