MV Need Help With Dynamically Building the Main Character Sprite in My Custom Plugin

Hello everyone,

I am trying to writer a plugin that dynamically builds the main character's sprite out of several different components, depending on the equipment they are currently wearing, but I am having some difficulties.
The Character tile set for my main character that is set in the Editor is called 'BodyLayer.png'.
BodyLayer.png

Currently I am just trying to layer one piece of equipment over it, it's 'EquipLayer1.png'
EquipLayer1.png

So the first thing I did was to modify
JavaScript:
Scene_Map.create()
so that the very first calls in it are reservation requests for those two sprite sheets to make sure they are loaded by the time I need them:

JavaScript:
ImageManager.reserveCharacter("BodyLayer");
ImageManager.reserveCharacter("EquipLayer1");
(I know I don't need the call for 'BodyLayer' since it's already being loaded because it is the sprite sheet selected for the character in the editor.)

Now my first question is, do I even need to call
JavaScript:
reserveCharacter()
or would
JavaScript:
loadCharacter()
work fine too, to make sure the assets are loaded in time. I am not entirely sure as to what exactly the difference between them is.

Now to actually changing the ingame player sprite. The sprite sheet for the player character is loaded in
JavaScript:
Sprite_Character.setCharacterBitmap()
by loading loading it into the propertiy
JavaScript:
bitmap
like so:
JavaScript:
this.bitmap = ImageManager.loadCharacter(this._characterName);
.

So (after checking that the function is currently working on the player sprite and not any other) I modified
JavaScript:
Sprite_Character.setCharacterBitmap()
:

JavaScript:
let bodyBitmap = ImageManager.loadCharacter(this._characterName);
let GearOneBitmap = ImageManager.loadCharacter("EquipLayer1");
let tempBitmap = new Bitmap(bodyBitmap.width, bodyBitmap.height);
tempBitmap.blt(bodyBitmap, 0, 0, bodyBitmap.width, bodyBitmap.height, 0, 0);
tempBitmap.blt(GearOneBitmap, 0, 0, GearOneBitmap.width, GearOneBitmap.height, 0, 0);
this.bitmap = tempBitmap;

I load the two sprite sheets (
JavaScript:
 ImageManager.loadCharacter(this._characterName)
just loads the sprite sheet that is selected for the main character in the editor, so in this case its: 'BodyLayer'), create an empty bitmap and perform two block transfers to write the contents of the two sprite sheets into the new bitmap (I know this is unoptimised, bear with me)

This does not work. The result is that the player character is completely invisible:
1636899754087.png

If I however walk my invisible character to a map transfer the layered image for my player displays correctly once the new map has loaded.
1636899786079.png

So my initial thought was that maybe the the sprite sheets aren't ready by the time I want to use them. So just to make sure that is not the case I changed the contents of my modifications of
JavaScript:
Sprite_Character.setCharacterBitmap()
to
JavaScript:
this.bitmap = ImageManager.loadCharacter("BodyLayer");
and
JavaScript:
this.bitmap = ImageManager.loadCharacter("EquipLayer1");
respectively and both of them work just fine:
1636899877602.png
1636899925654.png

The images individually work just fine, so I assume they are indeed loaded in time. Next I tried
JavaScript:
this.bitmap = ImageManager.loadCharacter(this._characterName);
let GearOneBitmap = ImageManager.loadCharacter("EquipLayer1");
this.bitmap.blt(GearOneBitmap, 0, 0, GearOneBitmap.width, GearOneBitmap.height, 0, 0);
But again that didn't quite work. it only draws the bitmap before the block transfer(blt) is applied for some reason:
1636899975171.png

It again corrects itself once you walk to another map:
1636899996763.png

So now I am left wondering, is the blt operation asynchronous too? Does it just not finish by the time the bitmap is used? If so, is there a way to know when the operation is finished?
JavaScript:
Bitmap
has a function
Code:
isReady()
, so I went back to my first implementation and added a check for whether
JavaScript:
tempBitmap.isReady()
. This just returned true despite the game only drawing an empty(invisible) character.
1636900040773.png

I am honestly at my wit's end and need somebody to explain to me what is going on and how to fix it. What confuses me the most is that everything works just fine once you transition to a new map, because once you do that the game goes trough
JavaScript:
Sprite_Character.setCharacterBitmap()
again in the same way, makes the same block transfers and everything, but this time it works for some reason. Hopefully someone can help me make sense of this.
you need to define a "refresh function" so it reload when something
is changed, otherwise, it doesn't refresh when map it loaded which
you want to do so.

there are 2 plugins to change the sprite (from startup, during game play),
depending how you want to use it.

both uses an ingame menu to do so, as well items to change dynamically
if you change a piece of armor.

you might want to check those out how they call it and see what is
relevant for yours to work.

SRD has DynamicActors..... and something with EX to change them,
there is also a visualEquip plugin and another, but they all work
differently, so you might want to check them out.

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-dynamically-building-the-main-character-sprite-in-my-custom-plugin.142120/