Unity Products:Amplify Shader Editor/External Nodes Dependencies

From Amplify Creations Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Product Page - Included Shaders - Manual - Shader Functions - Tutorials - API - Shader Templates - Nodes - Community Nodes

Introduction

Amplify Shader Editor allows other plugin developers to create and distribute their custom nodes in order doing some type of integration of their plugin with ours. This leads to how can a developer share their custom node with a user which might not ASE so their code doesn't generate compilation error.

Detect Amplify Shader Editor

When used, Amplify Shader Editor registers the AMPLIFY_SHADER_EDITOR Scripting Define Symbol over the project Player Prefs. This allows developers to encapsulate their custom node under an #if #endif so its source code is only compiled if ASE is on the Project folder.

#if AMPLIFY_SHADER_EDITOR
namespace AmplifyShaderEditor
{
	[System.Serializable]
	[NodeAttributes( "Node Name", "Node Category", "Node Description")]
	public class MyCustomNode : ParentNode
	{
		(...)
	}
}
#endif


Release Dependency

Unity does not offer any type of mechanism for developers to know and take actions when their plugins are being removed from a project. What this means is when Amplify Shader Editor is removed from the project, it does not have the capability to remove the Scripting Define Symbol from the Player Prefs. This will lead to compilation errors since source code depending on our plugin will be be incorrectly compiled. If falls to the developers using Amplify Shader Editor to prevent this from happening. Here's a small snippet how to detect if ASE is installed and remove the AMPLIFY_SHADER_EDITOR symbol accordingly.

public static void CheckIfASEOnProject()
{
	string AmplifyShaderEditorDefineSymbol = "AMPLIFY_SHADER_EDITOR";
	string AmplifyShaderEditorMainGUID = "c8bcac0d66f920e49803925a85beb0ed";

	if( !File.Exists( AssetDatabase.GUIDToAssetPath( AmplifyShaderEditorMainGUID ) ) )
	{
		string currData = PlayerSettings.GetScriptingDefineSymbolsForGroup( EditorUserBuildSettings.selectedBuildTargetGroup );
		int index = currData.IndexOf( AmplifyShaderEditorDefineSymbol );
		if( index > -1 )
		{
			currData = currData.Replace( AmplifyShaderEditorDefineSymbol, string.Empty );
			PlayerSettings.SetScriptingDefineSymbolsForGroup( EditorUserBuildSettings.selectedBuildTargetGroup, currData );
		}
	}
}

Choosing where to call this function is not an easy task and heavily depends on the plugin. The errors generated by the plugin dependency on ASE may prevent it from cleaning the symbol.
This is mostly because compilation errors on c# scripts prevents other scripts from running thus blocking functionalities from being called.

The following situations must be taken into account:

  • Import ASE > Remove ASE > Import Other plugin
  • Import ASE > Import Other plugin > Remove ASE / Import Other plugin > Import ASE > Remove ASE