Character Sprites already need to be iterated to be updated. Why not just throw a flag on the Game_Event object whose sprite you are going to remove and have it remove the sprite on the next iteration?
class Spriteset_Map def update_characters refresh_characters if @map_id != $game_map.map_id @character_sprites.each {|sprite| if sprite.to_be_removed sprite.dispose @character_sprites.delete(sprite) else sprite.update end } end endclass Sprite_Character def to_be_removed @character ? @character.delete_sprite : false end endclass Game_CharacterBase attr_accessor :delete_spriteendThen you could set the flag right before you remove the event from @events in Game_Map. Since the event is set for destruction anyway, you are removing its last reference when you remove the sprite (which has a reference back, via @character), you take care of that problem as well.Or, if you don't feel like modifying any of the underlying structure at all, you could simply maintain another reference list that points back to the sprite. Just register your sprite in the a when you create it, then you'll have a direct reference for when you remove it. Use a class variable here because you do not want any of the sprite data in your savegame. Use a hash with the actual character object as the key since @character_sprites are not limited to just events (hash lookups are generally pretty fast, but using an entire character object as a key may slow it a bit, so adjust this as necessary). You could have just created a global hash that simply pairs without the access method, but I liked this way better:
class Game_CharacterBase @@sprites = {} def sprite @@sprites[self] end def register_sprite(s) @@sprites[self] = s end def detach_sprite @@sprites.delete(self) endendclass Sprite_Character alias init_mith_charref initialize def initialize(*args) init_mith_charref(*args) @character.register_sprite(self) if @character end alias character_set_mith_charref character= def character=(char) @character.detach_sprite if @character character_set_mith_charref(char) @character.register_sprite(self) if @character endendThe problem there is that since you would (presumably) be using a Game_Map method to manage the removal of events, you would need to punch through a few layers of encapsulation (SceneManager > Scene > Spriteset) to be able to actually access the character_sprites array, which is a bit ugly. At that point I would probably have a public instance 'to be destroyed' array in Game_Map where I would move the events removed from @events, then remove the associated sprites when updating Spriteset_Map, detach the sprite from the event, and clear the array to remove the last reference.It would be less overhead in the long run, I suppose. It sounded cleaner in my head, anyway, than re-iterating through it if you have already iterated through it.
EDIT (just before posting)
@Shaz: To your original post, you can't just dispose the sprite from within the Sprite object, because you need to also remove it from the array in Spriteset_Map. You can punch through all the encapsulation, but it is really quite ugly.
To your last post, you shouldn't keep an instance variable for @sprite in Game_CharacterBase, because they are associated with savegames and sprites cannot be dump'd (you could define one for them, but you don't need or want them to)