The native C2 save/load system appears to forget the "disabled collisions" state of Physics objects.
After loading, all Physics collisions are enabled regardless of prior state.
The Physics behavior has an option to "Disable Collisions" between objects, on an object-by-object basis.
I'll refer to the data structure that stores that inter-object collision info, as the "collision relationships list".
e.g. Given SpriteA, SpriteB, and SpriteC, you could disable collisions between only SpriteA and SpriteC.
All other collision combinations would still occur normally.
When using the native C2 save/load system, if you save, and then load, the Physics behavior's "collision relationships list" state is not restored.
After loading, all collision relationships are set to enabled.
Attach a Capx
Description of Capx
Image of the capx.
The capx shows a real-time interactive demo of the problem.
There's text in the capx to explain steps to execute and what to look for.
The capx shows two physics enabled sprite objects, a static (Immovable) Orange box, and a moving Blue box.
The moving blue box is attracted to the Red "X" which drags it back and forth in a horizontal sine motion.
On layout start, collisions between the blue mover box and orange static box are disabled.
This allows the blue mover box to pass through the static orange box without colliding.
At the bottom of the canvas are 5 buttons.
- Save: Save game state via native C2 save/load system.
- Load: Load game state via native C2 save/load system.
- Set no-hit: Disables collisions between Mover & Static.
- Restart: Restarts layout.
- Toggle text: Show/Hide text.
Steps to Reproduce Bug
Run the capx.
- Observe the blue box passing through the orange box without colliding.
This is due to the event: On start, disable collisions between those objects.
- Click the "Save" button, to save the game via C2's native save/load system.
- Click the "Load" button, to load the last save state.
- Observe the blue box now collides with the orange box.
The disabled collision state has not been restored.
You can optionally experiment a little further:
- Click the "Set no-hit" button to re-disable collisions.
- Observe, the boxes no longer collide.
- Retry clicking the "Save" and then "Load" buttons.
- The boxes now collide again.
The Physics behavior's "collision relationships list" is not restored after loading the game state, and so the boxes begin colliding with each other.
The "collision relationships list" is restored after loading the game state, the disabled collision status between the boxes is likewise restored. and so the boxes pass through each other without colliding.
- NW.js: YES
- Chrome: YES
- FireFox: YES
- Opera: YES
- Iron: YES
- Internet Explorer: YES
Operating System and Service Pack
Win7 x64 - Pro
Construct 2 Version ID
Release 247 (64- bit) checked
Built at 13:33:48 on Sep 21 2017