Script not getting component?

Ok so right now i’m working on a selection script and I can’t seem to get a variable in another script work out properly. Before I added the new stuff it worked fine, and I just kept the same thing, but now doesn’t seem to work.

When there is a selected object it should send the pathEnabler to equal true, but it doesn’t seem to be sending, or there is something disabling it that I can’t see.

The place is at 24-27 lines:

using UnityEngine;
using System.Collections;

public class CamSelection : MonoBehaviour {
public GameObject PSselected;
private GameObject PSselectedClone;
public GameObject PSwaiting;
private GameObject PSwaitingClone;
public GameObject PSenemy;
private GameObject PSenemyClone;
private Transform myTransform;
private GameObject cachedObj;
private GameObject objCached;
private GameObject slcObj;
private GameObject enmObj;
	// Use this for initialization
	void Start () {
		myTransform = transform;
	}
	
	void Update () {
		GetTarget ();
		
		if(slcObj) {
			PathMaker pathMaker = slcObj.gameObject.GetComponent<PathMaker>();
			pathMaker.pathEnabler = true;
		}
		
		if(Input.GetKeyDown(KeyCode.Escape)) {
			slcObj = null;
			enmObj = null;
		}
	}
	
	private void GetTarget () {
		Ray ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
		RaycastHit hit;
		if(Physics.Raycast(ray/*Starting Point*/, out hit/*Direction of Ray*/, Mathf.Infinity/*Distance of ray*/)) {
			if(hit.collider.tag == "Player1" | hit.collider.tag == "Player2" | hit.collider.tag == "Player3" | hit.collider.tag == "Player4" | hit.collider.tag == "Player5" | hit.collider.tag == "Player6" | hit.collider.tag == "Enemy") {
				objCached = hit.collider.gameObject;
				if(Input.GetMouseButtonDown(0)  hit.collider.tag != "Enemy")
					slcObj = objCached;
				if(Input.GetMouseButtonDown(0)  hit.collider.tag == "Enemy")
					enmObj = objCached;
			}else{
				objCached = null;
			}

			if(objCached != cachedObj) {
				cachedObj = objCached;
			}
		}
		
		if(cachedObj  !Input.GetMouseButton(1)  !slcObj  !enmObj) {
			if(!PSwaitingClone) {
				Vector3 bullseye = cachedObj.transform.position;
				bullseye.y = cachedObj.transform.position.y-cachedObj.transform.position.y;
				PSwaitingClone = Instantiate(PSwaiting, bullseye, Quaternion.identity) as GameObject;
			}else{
				Vector3 bullseye = cachedObj.transform.position;
				bullseye.y = cachedObj.transform.position.y-cachedObj.transform.position.y;
				PSwaitingClone.transform.position = (bullseye);
			}
		}else{
			Destroy(PSwaitingClone);
		}
		
		if(slcObj) {
			if(!PSselectedClone) {
				Vector3 bullseye = slcObj.transform.position;
				bullseye.y = slcObj.transform.position.y-slcObj.transform.position.y;
				PSselectedClone = Instantiate(PSselected, bullseye, Quaternion.identity) as GameObject;
			}else{
				Vector3 bullseye = slcObj.transform.position;
				bullseye.y = slcObj.transform.position.y-slcObj.transform.position.y;
				PSselectedClone.transform.position = (bullseye);
			}
		}else{
			Destroy(PSselectedClone);
		}		
		
		if(enmObj) {
			if(!PSenemyClone) {
				Vector3 bullseye = enmObj.transform.position;
				bullseye.y = enmObj.transform.position.y-enmObj.transform.position.y;
				PSenemyClone = Instantiate(PSenemy, bullseye, Quaternion.identity) as GameObject;
			}else{
				Vector3 bullseye = enmObj.transform.position;
				bullseye.y = enmObj.transform.position.y-enmObj.transform.position.y;
				PSenemyClone.transform.position = (bullseye);
			}
		}else{
			Destroy(PSenemyClone);
		}
	}
}

No other scripts in my scene can possibly be disabling it.

(And yes this script is very messy and not very efficient, I just want to get it all working well enough to clean it up.)

debug it…

if(slcObj) {
Debug.Log(slcObj);
Debug.Log(slcObj.gameObject);
Debug.Log(slcObj.gameObject.GetComponent<PathMaker>());
PathMaker pathMaker = slcObj.gameObject.GetComponent<PathMaker>();
pathMaker.pathEnabler = true;
}

I debugged and it does indeed have the object selected, but the script on that object named PathMaker with the variable pathEnabler is still staying at false.

keep debuging…

if(slcObj) {
PathMaker pathMaker = slcObj.gameObject.GetComponent<PathMaker>();
pathMaker.pathEnabler = true;
Debug.Log(pathMaker.pathEnabler);
}

Well this is interesting, that debug comes back as true but the game nor the inspector are showing it as being true. Now i’m super confused…

The first variable pathEnabler is not checked :open_mouth:

Here is a better screen of the whole situation:

Click to enlarge image

Any ideas?

Can we see the code for PathMaker? Perhaps something in there is setting it.

I commented out the only thing that could affect it on line 60. And the clear line function isn’t called right now. There is nothing getting the component in the script on line 79, so there is no need for that script atm.

No Longer Available. Sorry

Also messy, deal with it for now.

What is this:

    void LateUpdate() {
        if(!isPath) {
            ClearLine();
        }
    }

Cross referencing your picture isPath is also false… thus, ClearLine is being called

Well that was it, that was an idea form before that never got erased… should always scroll to the bottom of my scripts… wow. .thanks. Lets just hope I don’t need that for my next stage. But yey ty for pointing that out to me.