I want to spawn an object in certain random points, which are animated and without using a button. So when the character spawns in the game the objects are spawning straight away

I am using UE 4.7.6,

I want to spawn objects which are animated and randomly, for example, when your at the fair there’s the game where you shoot targets and theres 2 rows, one is going to the left and one is going to the right. I would like to create something like that.

Hi,

I will try to explain it using your shooting target example.

First, place some target points in your level (your can search for them on the left). These are acting like a location marker, so you can decide the possible spawn locations for your obstacles. Place as many target points, as many possible spawn locations you want to have, and the game will choose randomly from these.

Now, create an ‘Actor’ Blueprint Class and add your obstacle static mesh to it as a component. This will be the obstacle that the Player needs to hit, so we will setup the logic that moves the obstacle after it spawned here. To do this, go to the ‘EventGraph’ and create an ‘EventTick’ event. This event will fire every frame. You can achieve the movement several ways, it mostly depends on how complex you want it to be. For example, you could create a ‘Speed’ variable that gets set randomly, so each obstacle will move at a different speed. But to keep it simple just add an ‘AddActorLocalOffaset’ node and hook it up with your ‘EventTick’. The ‘DeltaLocation’ determines the direction the actor will move, this is something that depends entirely on your scene, so chhose the right axis. You also want to check for ‘Sweep’.

The last thing to do is actually spawning the obstacles, because so far we only told them what to do when they spawned. Probably the easiest way for now is to use the LevelBlueprint. Create an ‘EventTick’ event here as well, but connect a delay node to it, and set the delay value to what you want (this will be the delay between the spaning of two obstacles). Connect a ‘GetAllActorsOfClass’ node to your delay, and set it to ‘TargetPoint’. This will find all the target points in your level and put them into an array. You want to choose a random TargetPoint from this array (the random spawn location) using the ‘Get’ node. Then, check fo the location of the randomly selected target point, and use that location for spawning the actor.

I attached a screenshot about the Level Blueprint setup, that shows what I just told you in text:

Keep in mind, that this is NOT an efficent, but a pretty simple solution to your problem, so if you are implenenting it for a real game, I would suggest you to avoid the heavy using of ‘EventTick’ events.

I hope this helps you a bit, feel free to ask if you are confused, I will try and help more.