How to find only active gameobjects

HI there,

     so i am making a script which has a publically declared varible. 
public GameObject playerShip;

then i assign the variable a gameobject

playerShip = GameObject.FindGameObjectWithTag("Player");

in the game i have a player selection screen. the user selects a ship, then plays. I have all 4 ships in the game scene. the one the user selects, remains active the other are inactive (by setactive(false)). All four ships have the tag, ‘Player’. the problem is that the gameobject variable randomly selects active or inactive ships. i want it to look for gameobject with tag which are only active.

thanks in Advance :slight_smile:
Note*I am a noob :stuck_out_tongue:

All the find functions of GameObject class looks for active gameobjects only as per the doc. Now you should check the other you set them inactive and call FindGameObjectWithTag. e.g.,

Try like this:

// First inactive Players tag game objects here, then find
playerShip = GameObject.FindGameObjectWithTag("Player");

instead of:

// First find Player tag gameobject 
playerShip = GameObject.FindGameObjectWithTag("Player");
// then inactive Players tag game objects here randomly.