Search Unity

How do you deal with References to optional Assemblies?

Discussion in 'Editor & General Support' started by col000r, Jan 31, 2019.

  1. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    699
    Imagine you have 2 scripts: Script A and Script B both do something useful on their own, but A has some extra functionality to work with B.

    All is fine and well until you try to split these two up to put them into separate assemblies. Now A doesn't know B exists. If I add a reference of assembly B to assembly A, everything is fine again.

    But now I want to be able to use A even if B is not installed!

    I can add a preprocessor directive around the B-specific functionality in A (#if B) and add it to the scripting define symbols.

    Now when I delete assembly B and remove the symbol B, all is well: I can use A without B.

    But if I then add B and forget to add the symbol B, I don't get the extra functionality and it's not trivial to see why not and how to fix it. Also the the process of setting all this up is painful!

    Is there an easier way?

    Very simple test project here