Detecting presence of, and calling functions in, another script

I have a script which needs to do two things:

(1) Detect the presence on another script in my project
(2) If the other script exists, call a function in it

I need to do this to make two libraries I am releasing seperatley work with each other if they are both present in the same Unity project.

What would be the best way to accomplish this?
So far I am playing with reflection, obscure OO ideas, eval inside a try/catch block, script 2 storing a function reference for itself inside a static variable of script 1, etc… I have a feeling I am, as usual, over thinking this.


I’ve never done anything like that, but since you asked, I tried this:

class SuperFunkyClass
	var funkyVar : String;

	static function getFunky () : void
		Debug.Log("Let's get funky");

function Start ()
	if ( SuperFunkyClass  &&  SuperFunkyClass.getFunky ) {

	if ( SuperFunkyClass  &&  SuperFunkyClass.getNifty ) {

	else {
		Debug.LogWarning("SuperFunkyClass can't get Nifty...");

It seems to do what I believe you describe.

Yep! I was overthinking it :slight_smile:
gameObject.AddComponent (“OtherLibrary”); worked perfectly. Thanks for your ideas!