Spawning Random Static Mesh

Hi UE4 Users

I’m trying to spawn a random static mesh to a target point but am having no luck. I’ve been trying to get this working for a week now and am getting desperate. :frowning:
I have created a few different blueprints. The first one below is supposed to tell the game what static mesh’s to spawn.
(BTW This blueprint is called Random Mesh)

This one is supposed to tell the game to spawn the mesh upon the player colliding with a box trigger

Any help would be deeply appreciated.
Thankyou :slight_smile:

Hi,

How does your two Blueprints communicate with each other? It seem like that you are getting a random integer from the array, but you are not doing anything with it. I’m in a hurry now, so there might be other problems needed to resolve, but at a first look, you should do something with the array element you just got.

I see two problems:

  1. If what youre showing is the entirety of the code for random mesh, then you have a problem. Youre setting up the array, sure. But you arent doing anything with it. The “GET” node needs to point to something (as evidenced by the unused output pin on the right). Get simply tells the software that youre pointing at that particular index in the array. Not what your code is supposed to be doing with said index.

  2. Your array is populated by actor references. The spawn actor node requires you to provide it with a class. I see how you attempted to address this (by trying to make a subroutine that returns a random mesh, but youre implementation is incomplete. You still pretty much elevate the mesh to a class so you can spawn said mesh inside random mesh.

My propsed fix:

  1. Scrap the random mesh blueprint.
  2. Make a blueprint class for each of the meshes you want to spawn (not best practice, but is quick dirty and easy). No code inside necessary, just the static mesh inside an actor blueprint class.
  3. Have another blueprint contain all the code from both pictures. But instead: make an array of actor classes NOT references (indicated by the color purple, NOT light blue). Hook up the unused “get” return pin to the class input pin on the spawn actor node.

Good luck!

Hi, thanks a lot for your response. I’ve fiddled around with it for a bit but cant seem to get it working. I’m confused with Step 3, sorry I am being useless but if you have the time could you upload an example image???
Thanks