Remove and RemoveAt for List not working
For some reason, the Remove() function does not seems to work in this particular case.
When my character enter the trigger of an object, this object is added to the interactables list. When my character exit the trigger of this object, this object is removed from the interactables list.
Although the object removed is contained in the list, it still doesn't work. Any idea?
List<GameObject> interactables = new List<GameObject>();
public void AddInteractable(GameObject interactable)
{
interactables.Add(interactable);
}
public void RemoveInteractable(GameObject interactable)
{
interactables.Remove(obj);
}
Thanks!
your Remove function isn't removing the game object passed to it...
Answer by nirharpaz · Oct 05, 2017 at 09:10 AM
public void RemoveInteractable(GameObject interactable)
{
interactables.Remove(obj);
}
did you try
public void RemoveInteractable(GameObject interactable)
{
interactables.Remove(interactable);
}
?
Your answer
Follow this Question
Related Questions
Unity Glitch or am i calling functions twice? List.Remove problem 0 Answers
Problem with Lists and Remove 0 Answers
How I randomise a list of signals in Unity and remove it from the list once the clip is finished? 0 Answers
Removing items from list by OnTriggerExit 2 Answers
Why is my listdisplaying that an item was removed? 0 Answers