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"

How to spawn random meshes in array

In this pic how where 'spawnActor BP Collectable' is, how do I use an array so it will spawn 1 random mesh (out of 5).

alt text

Product Version: UE 4.16
more ▼

asked Jul 20 '17 at 12:17 AM in Blueprint Scripting

avatar image

43 26 31 38

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

1 answer: sort voted first

I think a setup like this is what you are looking for:

alt text

  1. The array in question is an array of Static Mesh Actors. DON'T use static meshes; they cannot be used in conjunction with the spawn actor class. No worries though, you can use any static mesh as a static mesh actor class anyway. Alternatively, you can also just use an array of static mesh actor classes, allowing you to skip the step of later of getting the class of the static mesh actors.

  2. Last index returns the index of the last object in the array, so we use that and 0 as the range for the random mesh. I know you said you have five meshes (so technically, you could also fill in 4 as the max range), but I think this way is a bit safer. Plus, you won't have to constantly change the max value in case you wish to add a 6th mesh or more.

  3. The "GetClass" function is necessary to get the class of the static mesh actor you put into the array. Of course, you could just make the array a class array, and skip this part entirely.

more ▼

answered Jul 20 '17 at 02:13 AM

avatar image

815 30 26 105

avatar image MattStH Jul 20 '17 at 02:31 AM

That's great thanks for helping your comment and picture made it clear and easy to understand.

(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