How do I get my block to automatically pick the newly spawned object on start up?

0 favourites
  • 8 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • I have a simple case where I have a tiled background object (ProjectileField) that spawns another tiled background object (Vines) in a different layer than itself.

    However, instead of picking the newly spawned Vines object and setting only its angle and position, it picks all of the other Vines already in the layout and sets all of their angles and positions. This only happens when I use a function to determine the correct layer to spawn it in. If I set the spawn layer to 1 (which is disabled in the screenshot) the picking works perfectly fine. Am I not allowed to use a function there? What am I doing wrong?

    Maybe useful added context:

    - The ProjectileFields are already in the layout, some spawn Vines, others don't.

    - I used a text object to see how many Vines are picked immediately after the Create action, the result is "-27-1-1-1-1..." meaning that 27 are picked the first time the ProjectileField On Created block runs, and then only 1 after that.

  • Small correction: I said that the Vines positions are set, but I actually meant their size.

  • Hmm, it seems a little odd that it doesn't work only for the first time. You could try System > Pick last created

  • Thanks, that got it working.

    As far as I can tell, this seems to be a bug with Construct. I made a test project to see if it'll still happen there and these are my results:

    The layout:

    The event sheet:

    The result:

    According to the debug, there are only 3 of the red tiled background objects during runtime, meaning the fourth one that should've been created from the event sheet isn't there.

    Am I supposed to report this somewhere?

  • I can confirm that this also happens with sprite objects, and also with the Sprite's Spawn another object action.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • The three objects are with index id 0, 1 and 2 on debugger.

  • I tried but I actually cannot reproduce this.

    The test project you posted has an error with the events. Your getLayer function returns 0 BUT it is set to return a string. So it fails to create the object in the first place, and then picks all objects by default. This appears to not be the issue in your actual project though where it's the correct type.

    I thought I had an idea at first (that your function doesn't return anything and thus it fails to create the vine, like in your testproject) but since pick last created fixes it I kinda doubt that that's the issue. You can try removing the condition "layerName = 'Neutral'" and just leave the else and see if that also fixes it, that would mean that the projectile field is not created on one of the three layers (Spy, Jun or Neutral) but some incorrect layer initially.

  • That was it, some of them at some point were placed into an effects layer. Sorry for all of the confusion, I honestly don't know how they got in there. And thank you.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)