Recycled actors die on respawn

NobodyX

  • *
  • Posts: 1228
I have a behaviour that, when an enemy is supposed to die, does the following:
creates an explosion effect actor
makes a sound
recycles self

But when the actors get recycled in the game, then they will explode immediately. This only happens when the player shoots the enemy with a bullet that recycles itself at the same time as the enemy does, if the player kills the enemy with something that does not recycle itself upon collision then this issue does not occur.

If I use "kill self" on the enemy instead, it works except will become slow quickly.

The thing is that I am only recycling actors which are created as recycled actors while the game is in progress. When I was having issues like this before I could fix it by only recycling actors that are created as actors and only killing actors already placed within the scene when it loads. But even though I am already doing that it still does not work.

Greg

  • *
  • Posts: 1260
I think I'll need to see the existing behavior to wrap my head around this one. 

NobodyX

  • *
  • Posts: 1228
This is it. I am going to upload the game to forge in a minute, too.

NobodyX

  • *
  • Posts: 1228
It's uploaded. Play the starting level and shoot some pedals when they come off the flower, then the new pedals will immediately explode.

It seems to happen randomly, sometimes when I place an object in the editor it will never occur, and other times when I place it it will occur every time. Also it happens with completely different actors.

Should this be moved to the bugs section?

NobodyX

  • *
  • Posts: 1228
Anyone have any ideas on what's happening here?

Legendary Hoamaru

  • *
  • Posts: 1088
Have you tried resetting the values of the snippet before recycling?  Have you tried placing debug statements in the collision code to see if it is registering another collision upon creation?

Edit: Ah, you uploaded the game, gonna check it out.

« Last Edit: June 03, 2011, 08:49:28 pm by Legendary Hoamaru »

NobodyX

  • *
  • Posts: 1228
There are no values to reset. What's in the screenshot is the entire behaviour.

Legendary Hoamaru

  • *
  • Posts: 1088
I can't find the game on Forge.  Do you have it set to private?

NobodyX

  • *
  • Posts: 1228
Yeah, because I meant for Greg to see it, but didn't want to release it for absolutely anyone to download (and still don't). If you want me to give you the game I can upload it somewhere and send you a link, because I'd like to avoid sharing it with everyone.

Legendary Hoamaru

  • *
  • Posts: 1088
That is alright with me.

NobodyX

  • *
  • Posts: 1228
OK, I sent a PM with a link.

I put a few different enemies which have this problem in the scene called "Start," which is also currently the chosen starting scene. Shoot the things they create.

Legendary Hoamaru

  • *
  • Posts: 1088
Contacts are never ended when two actors collide and both recycle, so this is a bug.

For a temporary fix, place this code in a big code block right after the recycle block:

Code: [Select]
if(actor.body != null)
{
var contact:b2ContactEdge = actor.body.GetContactList();

while(contact != null)
{
scene.world.m_contactListener.EndContact(contact.contact);
contact = contact.next;
}
}

Let me know if there are problems related to this or if it's inefficient speed wise.  My tests seemed to run fine.

NobodyX

  • *
  • Posts: 1228
Works great, thanks!

NobodyX

  • *
  • Posts: 1228
I am having issues with this. When I have this code attached to enemies, when the player bullet hits and recycles the enemy then the bullet (that is supposed to recycle on collision) might randomly survive the collision (about 80% of the time).

Also, this should be fixed without the use of a workaround.