This is the way I have been removing objects from a list and making sure that they are not null:
public void RemoveFromList(Transform targ){
List<Transform> tempList = targetList;
for(int i = 0; i < targetList.Count; i++) {
if(targ == targetList*){*
_ tempList.Remove(tempList*);_
_ break;_
_ }_
_ }_
_ targetList = new List();_
_ for(int i = 0; i < tempList.Count; i++) {_
_ if(tempList != null){
targetList.Add(tempList);
}
}
}*
My question is: Is this alright to do? How taxing is it to recreate lists on the fly like this? These lists do not contain many objects(yet) and I havent noticed any performance issues. I would like to plan for adding more objects to these lists and multiple calls to this function from different objects, but I am unsure if this is the correct method to do this or if there is a better way.
Thanks_