Issue with "TypeError Cannot read property 'width' of undefined", please help!

Hi there,

I've been working on a game, using RPG Maker MZ, for some time now, but I'm encountering a problem I can't seem to fix. I've been going through the forums, without any luck. This is my first time posting a question online, and I hope someone can help me! I have no real coding experience...

So, about the error: There are a lot of random encounters in the game, and sometimes with a random encouter, I suddenly get the error "TypeError Cannot read property 'width' of undefined". I exchanged the images, no luck. I switched off my plugins (SRD and CGMZ), no luck. All my enemies and troops are consistent and don't refer to any deleted images or anything.

I switched on DevTools, and this is the error-message I got. I hope someone can help me understand this! If I'm posting this wrong/in the wrong place, please let me know!

rmmz_managers.js:2030 TypeError: Cannot read property 'width' of undefined
at Sprite_Enemy.updateFrame (rmmz_sprites.js:1003)
at Sprite_Enemy.Sprite_Battler.updateMain (rmmz_sprites.js:504)
at Sprite_Enemy.Sprite_Battler.update (rmmz_sprites.js:485)
at Sprite_Enemy.update (rmmz_sprites.js:961)
at Sprite.update (rmmz_core.js:1971)
at Sprite.update (rmmz_core.js:1971)
at Spriteset_Battle.Sprite.update (rmmz_core.js:1971)
at Spriteset_Battle.Spriteset_Base.update (rmmz_sprites.js:3162)
at Spriteset_Battle.update (rmmz_sprites.js:3627)
at Scene_Battle.Scene_Base.updateChildren (rmmz_scenes.js:129)
SceneManager.catchNormalError @ rmmz_managers.js:2030
SceneManager.catchException @ rmmz_managers.js:2018
SceneManager.update @ rmmz_managers.js:1941
Graphics._onTick @ rmmz_core.js:800
TickerListener.emit @ pixi.js:9474
Ticker.update @ pixi.js:9928
Ticker._tick @ pixi.js:9679
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
requestAnimationFrame (async)
Ticker._tick @ pixi.js:9682
It implies that one or more enemies involved do not have an image at the point when the error occurs. Ideas:
  1. Check your enemies! Make sure all enemies have an image assigned. I guess you've already checked, but it's best to make sure. 👋

  2. Check your troops! Maybe some of them have enemies without images. If you test a troop and the error occurs, press the Clear button to remove all enemies then re-add the enemies that should be there.

  3. Check your plugins! After making any changes in the Plugin Manager, save your project. If you don't save before testing, those changes will not be seen during test.
Also, note that you can update your project's core scripts to a newer/older version via Game > Update Corescript from the editor's menu bar. Newer versions have various bug-fixes, details here:
I'm mentioning this because your error message reports line number 1003 but I think that would be 1004 in v1.3.2 of the core scripts. 😅
basically the key part of the error message is the "of undefined".
that always means that the engine is missing a data object, either because you deleted the object in the database without removing it everywhere it was used, or because of a plugin data conflict.

In this specific case I agree that it is most likely a missing enemy since you already replaced the images of all enemies you believe to be used - which rarely include forgotten and invisible references to deleted enemies.
Wow, thanks a bunch, caethyril for your detailed and helpful answer!
Finally the issue seems to have been resolved...I reset all the plugins again, which didn't seem to work, but then I replaced one of the enemy-images I created with a new version version (just saved the .png again, no modifications, but gave it a different name), and that seems to have done the trick somehow...

I also updated the corescript, thanks for pointing that out!

Thank you very much!!! This was a great first experience of asking a question here ^.^

It implies that one or more enemies involved do not have an image at the point when the error occurs. Ideas:
  1. Check your enemies! Make sure all enemies have an image assigned. I guess you've already checked, but it's best to make sure. 👋

  2. Check your troops! Maybe some of them have enemies without images. If you test a troop and the error occurs, press the Clear button to remove all enemies then re-add the enemies that should be there.

  3. Check your plugins! After making any changes in the Plugin Manager, save your project. If you don't save before testing, those changes will not be seen during test.
Also, note that you can update your project's core scripts to a newer/older version via Game > Update Corescript from the editor's menu bar. Newer versions have various bug-fixes, details here:
I'm mentioning this because your error message reports line number 1003 but I think that would be 1004 in v1.3.2 of the core scripts. 😅
basically the key part of the error message is the "of undefined".
that always means that the engine is missing a data object, either because you deleted the object in the database without removing it everywhere it was used, or because of a plugin data conflict.

In this specific case I agree that it is most likely a missing enemy since you already replaced the images of all enemies you believe to be used - which rarely include forgotten and invisible references to deleted enemies.
Thanks, Andar! Indeed it seemed to be connected to the enemy images!

Original thread: https://forums.rpgmakerweb.com/threads/issue-with-typeerror-cannot-read-property-width-of-undefined-please-help.138873/