Select Random Mesh On Spawn

Hey all,

Was wondering if anybody had a way for an Actor to pick from a selection of meshes (ideally modifiable in Blueprint) when it’s spawned? I basically want to spawn the same class of object but select a random mesh from a selection that I give it. Is there a more compressed/streamlined way of doing it than creating lots of mesh UPROPERTY’s and assigning one in the constructor/begin play function?

I believe having TArray of U(static/skeletal/etc)Mesh inside actor would do the trick, you can add or remove elements of the array inside Blueprints editor.
During spawn get random number in range of 0 to array size and set mesh component property to use the mesh you chose.

Thanks BiggestSmile :slight_smile:

So, would the TArray expose a list in the Defaults view that I could plug assets into or would I have to do it inside the event graph do you think?

I think as long as you setup the EditDefaults in C++, it would expose a list for defaults inside of the Blueprint editor. Not sure of the specifics right now, it shouldn’t be too hard really.

As WarheadKillor said, adding EditDefaults specifier will allow you to edit the property in defaults tab, you can also add BlueprintReadWrite specifier if you want to change your array dynamically at run-time via Blueprints.