Custom Inspector: Targets & GameObjects

Hello, I’m having trouble figuring out how to get and edit gameObject data from the selected targets. I basically want to enable and disable certain children of the selected gameobjects depending on an int value on a script inside them;

I serialized the targets which I used to get the int value - that works

 m_Object = new SerializedObject(serializedObject.targetObjects);
 m_TunnelState = m_Object.FindProperty("Slider");
(Then use "m_TunnelState.intValue" to get int)

But I can’t seem to get the gameobjects in a similar way, to do the normal stuff like “ = false”

I already tried the following, but clearly it is wrong:

FloorTile[] Current = (FloorTile[])m_Object.targetObjects;
		foreach(FloorTile Tile in Current)

(‘FloorTile’ is the script which this editor is being used on)

I get ‘InvalidCastException: Cannot cast from source type to destination type.’ when selecting and deselecting multiple gameobjects

thanks, sorry for the long post

targetObject returns an Object. You’ll need to cast that into a GameObject (if it indeed is one) before you can do anything with it. Now, I don’t know what FloorTiles is, I assume it’s a class that’s attached to a GameObject…

Object[] currentSelection = m_Object.targetObjects;
    foreach(Object obj in currentSelection)
        if(obj is GameObject){
           Debug.Log( ((GameObject)obj).GetComponent<FloorTile>().name );

I wrote this straight here, so it’s untested. Let me know if it works or if I’m way off.