4ian / GDevelop

🎮 Open-source, cross-platform 2D/3D/multiplayer game engine designed for everyone.
https://gdevelop.io
Other
10.82k stars 848 forks source link

ForEach() does not include objects that were created the same frame (when using an Extension function) #2414

Closed tristanbob closed 3 years ago

tristanbob commented 3 years ago

Describe the bug

ForEach() does not include objects that were created the same frame (when using an Extension function)

To Reproduce

See project file. Includes a test using normal events (no problems) and a test using an extension function (causes problem).

Live Game

https://games.gdevelop-app.com/game-959d24dc-50bd-4d65-9fdd-47e0acee60c4/index.html

Project files

ChainOfObjects-BugTest.zip

Video

https://user-images.githubusercontent.com/8879811/110252697-e6675480-7f43-11eb-88da-0014d8e1c1e8.mp4

arthuro555 commented 3 years ago

The issue seems to be coming from the fact that runtimeScene.getObjects return always the latest objects list including the newly created objects, while eventsFunctionContext.getObjects returns the objects from when the events function was called, before creating the objects. Not sure if it is intended behavior or not.

4ian commented 3 years ago

The issue seems to be coming from the fact that runtimeScene.getObjects return always the latest objects list including the newly created objects, while eventsFunctionContext.getObjects returns the objects from when the events function was called, before creating the objects. Not sure if it is intended behavior or not.

Correct. I think we should:

  1. Update createObject so that we add the created objects to the objects lists passed as parameters.
  2. Remove the optimization that precompute object arrays for the eventsFunctionContext.getObjects. I'm not even sure it's that useful. EDIT: actually let's keep it, we can update the array in the createObject too.
tristanbob commented 3 years ago

Thanks for fixing this so fast, guys! This was holding me back to finish this object chain extension. :)

tristanbob commented 3 years ago

I can confirm that the nightly build has this fix and it works as expected.