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

Weird behavior on actor clone #2575

Closed
robly18 opened this issue Feb 12, 2023 · 7 comments · Fixed by #2576
Closed

Weird behavior on actor clone #2575

robly18 opened this issue Feb 12, 2023 · 7 comments · Fixed by #2576
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior

Comments

@robly18
Copy link

robly18 commented Feb 12, 2023

(Wasn't there a template for bug reports somewhere? I couldn't find it this time around.)

Excited as I was for the clone bug fix, I continued working on a side project of mine, but ran into some weirdness. After a lot of second guessing myself, I've reached the conclusion that the current method for actor cloning has a bug in it somewhere.

This example is being run on Excalibur v0.28.0-alpha.628+017953a.

Minimal Working Example

import "regenerator-runtime/runtime";

import * as ex from 'excalibur';
import {vec, Actor, Color, CollisionType, Engine} from 'excalibur';

const game = new Engine({
  width: 800,
  height: 600,
});

game.start();

const paddle = new Actor({
x: 150, y:  40,
width: 200, height: 20,
color: Color.Chartreuse,
collisionType: CollisionType.Active,
});
game.add(paddle);

const paddle2 = paddle.clone();

paddle2.pos.x = 400;
paddle2.color = Color.Red;
paddle2.on('collisionstart', (ev)=>{console.log(ev);});
game.add(paddle2);

ex.Physics.useRealisticPhysics();
ex.Physics.gravity = vec(0,60);

const wall = new Actor({
x: 100, y:  400,
width: 200, height: 20,
color: Color.Black,
collisionType: CollisionType.Fixed
});
game.add(wall);

Expected Behavior

One should see two falling physics objects, paddle and paddle2, and a wall below paddle. paddle2 should be a copy of paddle, but with a different x coordinate and a different color. There is a collisionstart event assigned to paddle2, which should never occur because it never collides with wall.

Actual Behavior

While paddle2 does indeed have a distinct x coordinate from paddle, the change in color to paddle2 also applies to paddle, which becomes red instead of chartreuse. Moreover, the collisionstart event is triggered when paddle collides with the wall.

Probable Cause

The deep copy which should be happening when paddle.clone() is called is probably not deep copying some of the object's components.

@eonarheim
Copy link
Member

(Wasn't there a template for bug reports somewhere? I couldn't find it this time around.)

There certainly was, I'll figure out what happened there!

This does seem like a bug in the cloning, I think you are right not everything must be copied correctly. It sounds like there is something off in the graphics component color change, and the collider component events at minimum.

@eonarheim eonarheim added the bug This issue describes undesirable, incorrect, or unexpected behavior label Feb 13, 2023
@eonarheim eonarheim mentioned this issue Feb 13, 2023
7 tasks
@eonarheim
Copy link
Member

@robly18 Does this show up for you when you click "new issue"?
image

@robly18
Copy link
Author

robly18 commented Feb 13, 2023

@robly18 Does this show up for you when you click "new issue"? image

Yeah, now it does. Don't know why it didn't yesterday, maybe I opened an issue in some weird way that automatically opened a blank issue. Thanks!

eonarheim added a commit that referenced this issue Feb 16, 2023
Closes #2575 

## Changes:

- Update Graphics layer cloning to clone individual graphics
- Update Collider Component cloning to clone stored colliders


## TODO:

* [x] Investigate ColliderComponent cloning to determine eventing issue
* [x] Look into other components closely
@eonarheim
Copy link
Member

Thanks @robly18 for reporting this!

@eonarheim
Copy link
Member

I've tested against your repro and I think we've got both issues sorted 👍

@robly18
Copy link
Author

robly18 commented Feb 16, 2023

No problem! Thank you for the excellent package.

As you can probably guess by my reports, I'm working on a project that uses Actor.clone() to some degree, so I'll be sure to report any weirdness I find!

@eonarheim
Copy link
Member

Thanks for the kind words!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants