MV Accessing a PIXI sprite child's index in SceneManager?

I have added a PIXI sprite to the scene using the following script call:

var mysprite = PIXI.Sprite.fromImage ("img/pictures/mysprite.png") SceneManager._scene.addChild (mysprite)

Now I'm trying to change/remove it via a separate script call (assuming the index of the added sprite is 0 or 1), but it doesn't work

I tried:
SceneManager._scene.children[0] SceneManager._scene.children[1] SceneManager._scene._spritesheet.children[1] SceneManager._scene._spritesheet._tilemap.children[1]

Clearly I'm missing something here but can't find the correct way of doing this anywhere, hopefully someone can explain
It's index is going to be last. SceneManager._scene already has 2 children, the spriteset map and window layer. So you might try SceneManager._scene.children[2]
However, I can't account for any plugins might have created their own children. Like cosmetic lighting or shadow plugins. So it could be anything.

You can inspect SceneManager._scene.children with something like
console.log(SceneManager._scene.children)

open the debug console during playtesting with f12.
Thank you! that was indeed the problem

However I noticed that once I open the menu scene and go back to the map scene, the sprite I added is gone. Is there another line that is needed in order to maintain it on the screen before/after "SceneManager._scene.addChild"?
Thank you! that was indeed the problem

However I noticed that once I open the menu scene and go back to the map scene, the sprite I added is gone. Is there another line that is needed in order to maintain it on the screen before/after "SceneManager._scene.addChild"?
This is because when you transition between the menu and the map, it actually reloads the map scene, thus any changes you made in code before entering the menu will no longer be there because it's a "fresh" map. You could programmatically rewrite Scene_Map's initialize function to add the child there, that would make it stop disappearing. But it would also only last for the current game session, and would persist if you loaded a save where the sprite wasn't meant to be there. Outside of plugins, there are few ideal solutions to this problem.
Thanks!
You could programmatically rewrite Scene_Map's initialize function to add the child there, that would make it stop disappearing. But it would also only last for the current game session, and would persist if you loaded a save where the sprite wasn't meant to be there.
the sprite is part of the HUD so it needs to be loaded whenever the map scene is loaded...
since I have a parallel event that constantly changes it, I thought of maybe adding the child within that same event, under a conditional branch that checks if the map scene was loaded?

I'm planning on creating my own menu scene anyway and disable the default one, so not sure if that's going to be an issue later

Original thread: https://forums.rpgmakerweb.com/threads/accessing-a-pixi-sprite-childs-index-in-scenemanager.155972/