Spawning object groups

I’m trying to spawn objects at 300 locations in a scene.

I want them to appear frequently and randomly at each location.

I’m using 2 object groups to be spawned:

  • snacks (energy boost)
  • spooks (game over) Each group has 5 different objects.

3 related problems:

  • Only the first object of each group is spawning.
  • Spawning is only occurring in the first 5 seconds of the game.
  • Spawning is only occurring at the first portion of the scene.

(The game is a raccoon climbing a 25-floor skyscraper. Each floor has 6 windows, and each window has a right and left side.)

Thanks for any thoughts,

Joe


First a few pointers:


  1. Don’t put beginning of scene inside a repeat event. Put the beginning of scene condition in its own event and then hang the repeat events off that as sub events.


  2. There is no need to use a trigger once if you change a variable in the conditions:


I think the issue is here:

That timer check is not a subevent of the repeat event. They are separate and unrelated events. The repeat does not have any influence on the one immediately after. So the actions of the event are performed on all the objects that meet the conditions, and any values set are all the same.

Change the events around you filter the objects first with conditions then use the repeat over the selected object. It should look like:

Thanks for responding - that did make a difference.

However, now spawned objects aren’t deleting/reseting until every available sill has been populated (about 20 seconds in), at which time all spawned objects delete at the same time and window sills begin to respawn again.

Also, only one object from both the snacks group and the spooks groups are spawning. Like only an apple, when I’d expect to see 4 other snacks, and one person, when I’d expect to see 4 other person-sprites. I suppose I can duplicate logic for each individual spawned object when it’s finally working, but I was trying to simplify by grouping.

Joe


Yes, because you are resetting the timer “LifeTimer” of the all the object in the group because you don’t have a condition to filter which group member to apply the timer reset:


so GDevelop applies it to all of the group objects. If you want to only apply it to the object created, then you’ll need to move the reset timer to after the create object action.


That’s because you are using the action “Create object SpooksGroup at position...”. So it creates the first object from that group. You want to use the “Create an object from it's name” action. This may require a slight rework of your objects, depending on how you’ve named them

I suggest you have a look at the example here on how to create a random object from a group.


I’ll also mention that this:

is not the most efficient way or the best practice for using repeats. It may not have an impact right now, but if you get into larger games it may be the difference between a smooth and a stuttering game. Reduce the number of objects first, then repeat over the filtered list:

Same goes for checking the “LifeTime” timer value in the “Snack and Spook Lifetimes” section.

Thanks, all that worked!

One new thing now is that 2 or more snacks are spawning at the same window sill at the same time, and same goes for spooks. It’s fine for a snack/spook to simultaneously occur at the same location, but not snack/snack or spook/spook.

I thought the condition: “The variable hasSnack of WindowSillRight = 0” would prevent multiple snack spawns in the same location, but that doesn’t seem to be the case.

Joe

In this event:


you are resetting the hasSnack and hasSpook variables, but you are not specifying which WindowSillLeft or WindowSillRight it’s for, so GDevelop will be doing it for all of them.

I suggest:

  1. You put WindowSillLeft and WindowSillRight into an object group named “WindowSillGroup”.
  2. Add a condition to check for collision between SnackGroup and WindowSillGroup to the first event.
  3. Move the “Delete SnackGroup” action to the first event.
  4. To the first event also add an action to set hasSnack of WindowSillGroup to 0.
  5. Remove the repeat for each instance event.

You can do without the repeat event here because the actions to delete doesn’t take any object specific or unique values. And the changing of the variable is to the same value for all the WindowSillGroup objects.

Snacks are now spawning correctly as the game progresses, but for some reason Spooks stop spawning after a dozen or so seconds. Seems like it must be because they’re not resetting properly, so they spawn once and never again. But the logic of both are identical, I believe.




Haha, you’re going to kick yourself for this one - in the very last event of your screen snips you’re resetting hasSnack, when it should be hasSpook.