Removing GameObjects from list (with List.Remove()) doesn't seem to be removing them

EDIT: Someone on a different forum told me to add if(!roomsInProg.Contains(currentRoom)) roomsInProg.Add(currentRoom); to my code, that fixed it, apparently i had duplicates on my list.


So i’m working on a dungeon generator in Unity and in my script I’m adding the rooms i generate to a list of rooms that are in progress, then remove it when its done generating and start generating the next one on the list.

here i’m setting the current room

currentRoom = Instantiate(roomPrefabs[Random.Range(0, roomPrefabs.Length)], new Vector3(0, 0, 0), Quaternion.identity) as GameObject;

then here i’m adding this room to the list of rooms in progress

roomsInProg.Add(currentRoom);

here is an example of me adding a new room that i spawned in to the list

if (roomScript.connectionsAvailable[0] == true && roomScript.rCheck[0].room == null && n<roomCount) {
        tempRoom = Instantiate(roomPrefabs[Random.Range(0, roomPrefabs.Length)], new Vector3(0, roomDistanceY, 0) + currentRoom.transform.position, Quaternion.identity) as GameObject;
        roomsInProg.Add(tempRoom);
        tempRoom.GetComponent<RoomScript>().directionFromSpawn = 0;
        n++;
        if (n>=roomCount) {
            firstOver = true;
        }
        }

and here i am removing the current room from the list

if (!firstOver) {
        roomsInProg.Remove(currentRoom);
        currentRoom = roomsInProg[0];
    }
    if (n<roomCount || roomsInProg.Count > 0) {
        Invoke("SpawnRoom", 0.01f);
    }
    }

Here is the entire code, if necessary using System.Collections;using System.Collections.Generic;using UnityEngine; - Pastebin.com Other Scripts if necessary RoomScript using System.Collections;using System.Collections.Generic;using UnityEngine; - Pastebin.com roomCheck using System.Collections;using System.Collections.Generic;using UnityEngine; - Pastebin.com SpawnCheck using System.Collections;using System.Collections.Generic;using UnityEngine; - Pastebin.com

try to put a debug log next to your removing code and see if its get executed or not
if not then logic not working

solved by adding if(!roomsInProg.Contains(currentRoom)) roomsInProg.Add(currentRoom); when adding the current room and if(!roomsInProg.Contains(tempRoom)) roomsInProg.Add(temoRoom); when adding the new rooms.