Copy Generic List?

Hi, its the first time i’m posting here. I am using playmaker , but i just start using c# for simple things.

I have a free script i found that called “waypointNode”, and uses a generic list that contains gameobjects( it says: public List <WaypointNode> neighbors;). Now i want from another script that i created to clear this list and i find out how to do it :

waypoint = go.gameObject.GetComponent<WaypointNode> ();

But what i want is to clear this list and after a few seconds to get it back again.
I think that i have first to copy this list to another, then clear the list and last copy the second list back to the first one.

I searching two days now for a solution in the forums, i have found same questions, but i cant find an answer that i can understand cause i am a beginner. Everything i try, i get errors.
Please help because i’m really confused about this, and please consider that i am a beginner.


public List neighbors;

List<WaypointNode> CopyList(List<WaypointNode> listToCopy)
	List<WaypointNode> newlist = new List<WaypointNode>();
	newlist = listToCopy;
	return newlist;

IEnumerator VanishAppear (List<WaypointNode> listToAlter, float delay)
	List<WaypointNode> temp = CopyList(listToAlter);
	yield return new WaitForSecondsRealtime(delay);
	listToAlter = temp;
	yield return null;

The way you’d call it in some script is:

StartCoroutine(VanishAppear(neighbors, 1f));

Where you can replace 1f with any float depicting how many seconds you want to pass between deleting the list and recreating it.

TheSOULDev, thanks for your reply.

I check your code and i really try to understand it, search the manual, but i dont get it. Especially the first part.
I make a mistake by telling that i want to clear the list for a few seconds. what i really want to do is to create a custom playmaker action that goes like this:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace HutongGames.PlayMaker.Actions
	public class WaypointClearAndRecreate : FsmStateAction
		public FsmOwnerDefault scriptOwner;//the owner of List <WaypointNode> neighbor
		WaypointNode waypoint;

		public List <WaypointNode> neighbors;

		public override void OnEnter()
			GameObject go = Fsm.GetOwnerDefaultTarget(scriptOwner);
			waypoint = go.gameObject.GetComponent<WaypointNode> ();

			//maybe here the new list is created?


		public override void OnExit()
			//here i want to recreate the list



I dont know how to use your code in my script. When i try to change it to fit my script, i get errors.
It’s the first time i try to work with lists so i dont get to much, and manual is hard to understand without certain examples.

Also, the neighbors list has only 4 elements, i dont know if this helps.