Change enemy's appearance after death

During battle, instead of an enemy disappearing after death, I'd like them to change into a different image (i.e. an injured version of themselves).

I've set the enemy's collapse effect to "No Disappear" but the moment I update the battlerName with `$gameTroop.members()[4].enemy().battlerName = "enemy_injured"` it disappears. Changing the battler name before the enemy dies seems to work fine. This is all reproducible by just using the debug console.

I've also tried adding and removing immortality, or increasing and decreasing HP with a battlerName change between, but it all results in the enemy image disappearing (an example of the latter is below).

1690293942577.png
Welcome!

Why not just make an entry in the enemy tab of your database for the legs and use the built-in Enemy Transform event command?

When you reference enemy.enemy() that's the database entry, not a property of that enemy object. You want to be changing the sprite on this specific enemy, not trying to modify the information loaded from the database.

What you actually want to do is more like:
Code:
BattleManager._spriteset._enemySprites[4].bitmap = ImageManager.loadEnemy("human_legs_injured")
Yea, just use the Transform Enemy command like Turan suggested. 😮‍💨
Spoiler: technical mumbling
(This is about behaviour without plugins.)

For layering purposes, enemy sprites are sorted by screen Y, then by member index, so you can't necessarily assume that the fifth enemy in the troop is _enemySprites[4]. The spriteset has a findTargetSprite method to help with that, which is normally used for animation/balloon positioning.

Setting the bitmap directly like that will work, but is a bit hacky. Anything that expects the sprite's _battlerName property to reflect its current bitmap (a reasonable assumption!) may malfunction. However, if you try to do it "properly" by modifying _battlerName instead, nothing will happen, because the sprite automatically refreshes its bitmap based on its assigned enemy's database record.

As mentioned, modifying the database data mid-game will affect all enemies of that type. It will also persist for the rest of the play session, i.e. choosing New/Load game will not reset it but closing the game will. That sort of thing is bound to cause bugs!
Thanks, @caethyril - I never got into it to realize the enemySprites don't necessarily correspond to the troop members.
Thank you for the advice and explanation, much appreciated! I tried the transform but the enemy is still disappearing. Debugger shows that the (invisible) troop member was indeed transformed to the injured version of the enemy. I set collapse to "no disappear" for the injured version of the enemy as well.
1690305255336.png


EDIT: The bitmap swap, however, worked fine:
Code:
BattleManager._spriteset.findTargetSprite($gameTroop.members()[4]).bitmap = ImageManager.loadEnemy("human_legs_injured")

Not a huge fan of hacks if it's supported natively, so I'm still interested if I'm doing something wrong with the transform event.
I'm not sure what to tell you...this works perfectly for me in my test project.

1 - first enemy has State Resist: Knockout

2 - troop event has when enemy HP <= 0%, transform into second enemy

3 - second enemy has Collapse: No Disappear
Thanks for checking. I see "State Resist: Dead" which I assume is the same? For me the enemy is transformed but not visible. I tried with entirely new enemies and troop with no luck.

Original enemy (I tried adding a collapse effect as well and that didn't change anything):
1690307471449.png


Transformed version:
1690307495166.png


Troop:
1690307520655.png


Here's the battle where I defeated the first enemy and see the battler name changed:
1690307449123.png
Yes, MZ calls it Dead.

Look at your plugins. Did you do what I did and test it in a new project?
I did it in my current project; I only have a few plugins I wrote myself, but I turned them off before testing (note the lack of "plugins" sources under "js":
1690328171563.png


Just created a new test project and I can still reproduce the problem. I tried transforming a Goblin to a Gnome:
Spoiler: Screenshots
1690328389385.png

1690328407984.png

1690328372895.png


1690328352392.png
So I apologize - I tested this setup on MV, which is why I referenced Knockout as the name of the state.

You are correct - in MZ there is a bug causing this to not work correctly.

The No Disappear trait by itself works properly, so that means something is bugged in the Enemy Transform portion.

I might try to look at it tomorrow unless @caethyril revisits the thread first and figures it out ('cause she's smart like that).
For what it's worth, I'm okay with the bitmap swap so don't investigate this on my behalf 🙂 I appreciate all your patience and help, thanks for stepping through this with me.
This troop event seems to work for me in MZ (condition: enemy HP (1) <= 0%):

◆Text:None, None, Window, Bottom : :Transforming! ◆Change Enemy HP:#1 Bob, + 1 ◆Enemy Transform:#1 Bob, Injured Bob ◆Wait:1 frame ◆Change Enemy HP:#1 Bob, - 1 (Allow Death)
The problem is that the enemy needs to be "alive" (present in battle and not dead) for the next sprite update, otherwise initVisibility will make the sprite invisible. So we heal up by 1 point, wait 1 frame for the sprite update (event still running, so battle is still paused), then kill them off. The "No Disappear" collapse effect is the "do nothing" option: it doesn't set the sprite on death or anything.
This troop event seems to work for me in MZ (condition: enemy HP (1) <= 0%)
I guess that's good to know/try to remember.

I think the confusion is that as I demonstrated above, in MV it works without having to manipulate the HP back and forth. So it seems like a logical error when it doesn't in MZ - initInvisibility must be getting applied in a different order, or function differently.
as I demonstrated above, in MV it works without having to manipulate the HP back and forth.
I don't know what's happening on your end (plugins?), but I just tried in a new MV project and I needed a Wait 1 frame there, too. Otherwise, just like in MZ, the sprite initialises to visible = false because it's dead.

You don't have to change the HP, e.g. you can put the "Resist State 1" trait on a state instead, then remove that 1 frame after transforming. You simply need to ensure the enemy is still alive when their sprite updates.

Original thread: https://forums.rpgmakerweb.com/threads/change-enemys-appearance-after-death.159696/