Null variable

Hi folks,I have a little problems that’s drive me in crazy. When I instantiate dinamically some gameObjects, I add to it a route and I want specify that route on a script named getRota. But I isn’t happening. When I test my application, they haven’t a route (getRoute.route=null). Someone can help me with this?

getRoute.cs:

public class getRoute : MonoBehaviour {
    
    public MonoBehaviour route;
    }

instantiateNPCwandering.cs:

void Start () {
   GameObject gmO=this.gameObject;
            			
   while(loop)
   {
       if(toClone!=null)
           gmO=Instantiate(toClone,transform.position+OnUnitCircle()*2,Quaternion.identity) as GameObject; 
            	
            			
           gmO.AddComponent ("wanderCircle");
            
           if(!gmO.GetComponent<getRoute>())
              gmO.AddComponent ("getRoute");
            
           gmO.GetComponent<getRoute>().route=(MonoBehaviour)gmO.GetComponent<wanderCircle>();
            
            		
            howMany++;			
            if(howMany==total)
               loop=false;
            		}		
            	}

It looks like you may need to go back to the drawing board with this. You have the right idea, but I feel you haven’t implemented it the best you could. I would have a NpcPath (or something like that) mono that encapsulates the state of the route, which route they’re currently doing, the ability to change that route…etc etc…

The design you have is too broken up and too small. You almost always see people do the exact opposite and throw too much code in one class rather than the other way around. The problem with yours is that you need multiple components to execute 1 idea. And that too violates the Single Responsibility Principle, only its on the unusually seen side of the spectrum.

A good rule of thumb: If you’re fighting your design constantly, you should step back and reevaluate it to see if it still fits the problem space.

recently I have to ask again about this (http://answers.unity3d.com/questions/451780/problem-in-assigning-a-random-route.html) and I already solved this. thanks for all