[SOLVED] Accessing function in another script not working, but returns no error.

I’m trying to access a public function in another script that’s attached to the terrain in my scene. The terrain is called terrain and is tagged Terrain, and has the script TerrainGenerate.cs attached to it, which has a public function called ActivateIdol().

I have another script, called TakeIdol.cs, with a function, TerrainSwitch(), that is called each time the player performs a specific action (confirmed to be working by placing a print() command within said function). I’m trying to call ActivateIdol() (in TerrainGenerate.cs) from within TerrainSwitch() (in TakeIdol.cs). The way I’m doing it is (from TakeIdol.cs):

public class TakeIdol : MonoBehaviour
{
	private GameObject terrain;
	...
	void Start ()
	{
		terrain = GameObject.FindGameObjectWithTag("Terrain");
		...
	}

	void TerrainSwitch()
	{
		terrain.GetComponent<TerrainGenerate>().ActivateIdol();
	}
}

But it’s not working. I’ve also tried modifying a public variable in TerrainGenerate.cs from TakeIdol.cs by doing:

void TerrainSwitch()
{
	terrain.GetComponent<TerrainGenerate>().timeNeeded = 10f;
}

but this is not modifying said public variable.
If I try to read that variable, like so:

void TerrainSwitch()
{
	print(terrain.GetComponent<TerrainGenerate>().timeNeeded);
	print("test");
	print("test " + terrain.GetComponent<TerrainGenerate>().timeNeeded);
}

the only output I receive is “test”.

What am I doing wrong…?

This is a shot in the dark but give this a try.

You currently have a try and catch statement in your update, put a print inside the catch and let me know if it gets in there.

The thing you have to watch with catching an exception and not doing anything with it is the compiler will just ignore it and not give you an error, i have a feeling this is what is happening.