Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R106 - C3 Runtime] Pin not working properly in the new runtime #1716

Closed
BonzerKitten opened this issue Jun 19, 2018 · 8 comments
Closed

[R106 - C3 Runtime] Pin not working properly in the new runtime #1716

BonzerKitten opened this issue Jun 19, 2018 · 8 comments
Assignees
Milestone

Comments

@BonzerKitten
Copy link

Problem description

I tried to switch to the new runtime in my main project, but when i do it the pin behaviour that hold the hat on top of the player head just stop working properly, and the main problem is that i just can't find a way to reproduce it in a separate project. I already tried to find the cause by checking the "find all references", but everything is OK, everything works just fine in the C2 Runtime, but not in the C3 Runtime, just like the problems with the Fade Behaviour (alredy fixed) and the Rotate Behaviour (alredy fixed).

Hat in the C2 Runtime: https://i.imgur.com/ikMyLMG.gif
In the C2 Runtime the Pin Behaviour is working with no problem.

Hat in the C3 Runtime: https://i.imgur.com/RofqYwa.gif
In the C3 Runtime the Pin Behaviour look like the combination of "Every Tick" + "Set Position" with that tiny delay.

Attach a .c3p

I can't post my main project here because it's a commercial product, but i can definitely send it via e-mail for a Scirra employee.

Steps to reproduce

  1. Choose the "C2 Runtime" in the advanced tab.
  2. Open and run the "lay_level_2" layout.
  3. Choose the "C3 Runtime" in the advanced tab.
  4. Open and run the "lay_level_2" layout.

Observed result

The "hat" have a tiny delay with the Pin Behaviour.

Expected result

The "hat" to be in the exactly same place as the player with the Pin Behaviour.

Affected browsers

  • Chrome: yes

System details

If you see a crash report dialog, please copy and paste it to where it says "PASTE HERE" below. Otherwise please go to Menu -> About -> Platform information and paste that information there instead.

View details

PASTE HERE

@AshleyScirra
Copy link
Member

Can you make a minimal repro by deleting down content from the full project? It is far easier to deal with that way.

@BonzerKitten
Copy link
Author

I may break the full project without some parts, but i'll try to remove as much as possible.

@BonzerKitten
Copy link
Author

Ok! I deleted enough to make the project unusable for anyone else. You just need to open the layout called "lay_level_2" and press "z" to jump and see the problem with the hat. The code related to the hat is inside a group called "gro_hat" in a event sheet called "eve_gameplay": https://i.imgur.com/b2G0uGg.png?1

Pin Bug Runtime.zip

@BonzerKitten
Copy link
Author

So, i found more problems while switching to the new runtime, please, take a look at this post i made on Imgur: https://imgur.com/a/xgFxvH2
Should i open a new issue for it?

@AshleyScirra
Copy link
Member

Minimal repro:
Duck Souls min repro.zip

@AshleyScirra
Copy link
Member

This is difficult. tl;dr: pin spr_hat to spr_player_collision instead of spr_player_graphic, and it works in the C3 runtime too.

The fundamental issue is you have a chain of pins: the hat is pinned to the player, and the player is pinned to the collision box. This is an awkward setup for the engine since it processes behaviors one at a time, and it has to pick some order to do them in. When it processes a pin, it moves the object to the correct location according to the pin. When you have a chain of pins, it only keeps them locked together if it processes them in reverse order from the root instance back (i.e. collision box, player graphic, hat). If it processes them in the other order (i.e. hat, player, collision) then there is a frame of lag, since the hat updates its position to the player, but then the player updates its position to a different position to move with the collision box, moving it away from where the hat is.

If you pin both the hat and the player to the same object, it avoids the problem since they're both pinned to the same thing and there is no chain. This is the obvious quick-fix for this project. However it exposes a deeper backwards compatibility problem with the C3 runtime that it can sometimes process behaviors in a different order to the C2 runtime, which is probably going to cause more problems in other situations.

The C2 runtime processes behaviors in order of object creation. Essentially it only works in the original project because you created the hat sprite after the player sprite. If you had created them the other way round, it would have lagged in the C2 runtime too. (The same workaround would fix that case too though.) The C3 runtime is designed to be more efficient and avoids processing behaviors that don't do anything, like unpinned pin behaviors. When you pin the behavior, it then starts processing it. The C3 runtime then processes the behaviors in the order they were pinned. Since the hat 'On created' event runs first, it pins the hat first, so processes the hat pin behavior first, resulting in a different order to the C2 runtime and a frame of lag.

While this project has an easy fix I think the only way to ensure the C3 runtime is 100% backwards compatible with the C2 runtime is to ensure it always processes behaviors in the same order, which is a bit awkward given the C3 runtime dynamically adds and removes behaviors for processing in order to save CPU time. I'll leave this issue open to work on that.

@AshleyScirra AshleyScirra added this to the Next release milestone Jun 21, 2018
@AshleyScirra
Copy link
Member

Alright, got some special sorting code in for the next release to ensure the C3 runtime processes behaviors in the same order the C2 runtime does, which appears to fix this.

For any other issues I'd wait until the next release in case they're related to this issue. If you still have trouble please file new issues for them following all the guidelines, and do your best to reduce it to an absolutely minimal project, as I attached previously - even the project you provided still has far too much content to feasibly debug.

@BonzerKitten
Copy link
Author

Thank you very much for this really nice explanation (remembered me about some of your blog posts) about the problem, it was very insightful!

In the full game we would still have a little problem if we just pinned the spr_hat in the spr_player_collision, because the spr_player_graphic is rotated while the player is dashing, so the spr_hat wont be able to automatically follow it's rotating, but we could easily fix that by adding an "every tick > set angle > spr_player_graphic.angle" to the spr_hat.

Anyway, i'll wait until the next release to see if everything is working before i open another issue, for now i'll keep working with the C2 runtime. Thank you for your attention, Ashley! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants