I have chains of connectable objects which reference eachother. Need them to pass a simple boolean to eachother! How?

So, basically I have a system where my character can place wire.
A little cube gets instantiated, and a new one starts following the mouse, with a linerenderer running the visual “wire”. At this moment the cubes get references to eachother. Then the second cube can get placed down, to either run another length of wire or to end the connection at a powerable object, right now I have a “lamp”.

We connect a lever to the first cube which triggers a function, “If the cubes we are connected to are not the same state as I am, make them the same state. and then trigger this same function on that cube’s script”

This was working well enough logic-wise but once I got further into the system, I realized doing all of this in frame-based loops was inefficient and killed my FPS.

So I started trying to convert my functions into coroutines, but I can’t seem to figure it out! I’ve gotten debug logs to show they are happening but the resulting behavior isn’t reflecting it.

I left in some commented code to show my trial-and-errors here.

public Coroutine Flip(){
		//state = !state;
		//StartCoroutine(PushState);//PushState ();
		StartCoroutine ("PushState");
		return null;	
		//yield return null;


	//public IEnumerator Flip() {
		//for(;;) {
	//		print ("Pushing state");
	//		PushState();
	//		yield return new WaitForSeconds(.05f);
	//	}

	WireNode node;
	public IEnumerator PushState(){

		print ("Pushing");

		foreach (Behaviour conn in ports) {
			if (conn != null) {
				if (conn.name.Contains ("WireNode")) {
					node = conn as WireNode;
					if (node.state != state) {
						node.state = state;
						node.PushState ();

					foreach (LineRenderer cable in node.wirelines) {
						if (node.state == true)
							cable.materials [0].color = onColor;
						if (node.state == false)
							cable.materials [0].color = offColor;


				if (conn.name.Contains ("Powerable")) {
					Powerable p = conn as Powerable;
					p.powered = state;
					p.StartRefresh ();


			} else {
				//yield return null;

		yield return null;


I need each wire to tell its own list of other connected wires what to do / what state they are in (boolean).

I plan to allow for a huge number of wires taking place at once, so I am hoping to condense the behaviour into one that is not framerate dependant, will not bog down the framerate

I only need this message / state to be changed once at a time. I.e., all of the wires are simply in one state, and not doing anything, until they are told to refresh, which is one action that pushes their state to other wires.

Like Redstone.

Take a look at this. You can try using yourOtherObject.SendMessage () to tell the next to do what ever it is you need to do.