MZ z-index not working.

I am trying to create a new topmost sprite, and tried creating a z-index, but cannot seem to get it to work. If I use 'this.addChild' after all display objects are rendered, it works, but if I try to use it before everything else is made, it doesn't. I want this to work with every scene, and don't want to manually add it for each and every scene. I have the zIndex set, and the scene's sortDirty is properly being set to true, but unless my sprite is the last child, it does not show.

JavaScript:
/*:
 * @target MZ
 * @plugindesc Zetu Cursor Script
 * @author Zetu/DrJosephJorgen
 * @help Help Text
 *
 * ---------------------------------------------------------------
 *
 * @param DefaultCursor
 * @text Default Cursor
 * @help Cursor to display when no other rules apply.
 * @type struct<Cursor>
 * @default {"CursorImage":"Cursor/Default","Ox":"0","Oy":"0"}
 *
 * @param DockCursor
 * @text Dock Cursor
 * @help Cursor to display when appending a child (other plugins only)
 * @type struct<Cursor>
 * @default {"CursorImage":"Cursor/UseItem","Ox":"0","Oy":"0"}
 *
 * @param DockOffset
 * @text Dock Cursor Offset
 * @help Offset of sub-bitmap to the cursor.
 * @type struct<XY>
 * @default {"X":"7","Y":"15"}
 *
 * @param Cursors
 * @text Other Cursors
 * @help Custom Cursors for miscellaneous uses.
 * @type struct<Cursor>[]
 * @default ["{\"CursorImage\":\"Cursor/Inspect\",\"Ox\":\"12\",\"Oy\":\"12\",\"AnimationEnabled\":\"false\",\"AnimationFrames\":\"1\",\"AnimationDuration\":\"12\",\"AnimationPingPong\":\"false\"}","{\"CursorImage\":\"Cursor/UseItem\",\"Ox\":\"0\",\"Oy\":\"0\",\"AnimationEnabled\":\"false\",\"AnimationFrames\":\"1\",\"AnimationDuration\":\"12\",\"AnimationPingPong\":\"false\"}","{\"CursorImage\":\"Cursor/Loading\",\"Ox\":\"0\",\"Oy\":\"0\",\"AnimationEnabled\":\"true\",\"AnimationFrames\":\"8\",\"AnimationDuration\":\"12\",\"AnimationPingPong\":\"false\"}"]
 *
 */
/*~struct~Cursor:
 *
 * @param CursorImage
 * @text Image
 * @type file
 * @dir img/system/Cursor
 *
 * @param Ox
 * @text X Offset
 * @type number
 * @default 0
 *
 * @param Oy
 * @text Y Offset
 * @type number
 * @default 0
 *
 * @param AnimationEnabled
 * @text Enable Animations
 * @type boolean
 * @default false
 *
 * @param AnimationFrames
 * @text Spritesheet Frames
 * @type number
 * @default 1
 * @parent AnimationEnabled
 *
 * @param AnimationDuration
 * @text Spritesheet Duration (100 = 1 second)
 * @type number
 * @default 12
 * @parent AnimationEnabled
 *
 * @param AnimationPingPong
 * @text Ping Pong Animation
 * @type boolean
 * @default false
 * @parent AnimationEnabled
 *
 */
/*~struct~XY:
 *
 * @param X
 * @text X
 * @type number
 * @default 0
 *
 * @param Y
 * @text Y
 * @type number
 * @default 0
 */
Zetu.setupHeader("Zetu_MZ_Cursor")
    .setNamespace("Cursor")
    .requires("Zetu_MZ_Core");

Zetu.note.namespace("cursor")
    .page(/ON HOVER (.+)/i, (page, cursor) => {
        page.cursorHover = cursor;
    })
    .page(/INTERACT DISTANCE (\d+)/i, (page, distance) => {
        distance = parseInt(distance);
        page.cursorTriggerDistance = distance;
    });

Zetu.Cursor.DisableStyle = new CSSStyleSheet();
Zetu.Cursor.DisableStyle.replaceSync('* { cursor: none; }');
document.adoptedStyleSheets = [Zetu.Cursor.DisableStyle];

// #region Scene_Boot
$gameCursor = null;
// #endregion

const ZETU_CURSOR_Scene_Base_initialize = Scene_Map.prototype.create;
Scene_Map.prototype.create = function () {
    ZETU_CURSOR_Scene_Base_initialize.call(this);
    this.addChild($gameCursor);
};
// Scene_Map.prototype.create = function() {
//     Scene_Message.prototype.create.call(this);
//     this._transfer = $gamePlayer.isTransferring();
//     this._lastMapWasNull = !$dataMap;
//     if (this._transfer) {
//         DataManager.loadMapData($gamePlayer.newMapId());
//         this.onTransfer();
//     } else {
//         DataManager.loadMapData($gameMap.mapId());
//     }
//     this.addChild($gameCursor);
//     //$gameCursor.children.forEach(c => this.addChild(c));
//     console.log(this.children);
// };

// #region Game_Cursor
function Spriteset_Cursor() {
    this.initialize(...arguments);
}

Spriteset_Cursor.prototype = Object.create(Sprite.prototype);
Spriteset_Cursor.prototype.constructor = Spriteset_Cursor;

Spriteset_Cursor.prototype.initialize = function () {
    Sprite.prototype.initialize.call(this);
    this.z = this.zIndex = 999;
    this.addChild(this.active = this.default = new Sprite_Cursor(Zetu.Cursor.DefaultCursor));
    // this.addChild(new Sprite_Cursor(Zetu.Cursor.DockCursor));
    // Zetu.Cursor.Cursors.forEach(options => this.addChild(new Sprite_Cursor(options)));
    // this.hover = null;
    // this.mode = null;
    // console.log(this.children);
    // console.log(this);
};

Spriteset_Cursor.prototype.update = function () {
    Sprite.prototype.update.call(this);
};

Sprite_Cursor.prototype.destroy = function () {
    console.log('destroy');
    // don't
};
// #endregion

// #region Sprite_Cursor
function Sprite_Cursor () {
    this.initialize(...arguments);
}

Sprite_Cursor.prototype = Object.create(Sprite.prototype);
Sprite_Cursor.prototype.constructor = Sprite_Cursor;

Sprite_Cursor.prototype.initialize = function (options) {
    Sprite.prototype.initialize.call(this);
    this.z = this.zIndex = 999;
    this.bitmap = ImageManager.loadSystem(options.CursorImage);
    this.ox = options.Ox;
    this.oy = options.Oy;
    this.name = options.CursorImage.split('/').last();
    if (options.AnimationEnabled) {
        const frames = options.AnimationFrames;
        const duration = options.AnimationDuration;
        const pingpong = options.AnimationPingPong;
        this.setupSpritestripAnimation(frames, duration, pingpong);
    }
    console.log(options);
    console.log(this);
    console.log(this.bitmap);
};

Sprite_Cursor.prototype.update = function () {
    Sprite.prototype.update.call(this);
    this.updatePosition();
};

Sprite_Cursor.prototype.updatePosition = function () {
    this.x = TouchInput.x - this.ox;
    this.y = TouchInput.y - this.oy;
}
// #endregion
$gameCursor = new Spriteset_Cursor();
Hi,

Did you check that your container has the "sortableChildren" attribute set to true ?
OK, that worked, and was not intuitive. Setting z index changes sortDirty = true, but I'm not sure why that property doesn't either.

Original thread: https://forums.rpgmakerweb.com/threads/z-index-not-working.171070/