Skip to content

Commit 62c3c05

Browse files
authored
Fixed an unhelpful error message when custom function nodes don't have a valid file (#4049)
1 parent a4aff57 commit 62c3c05

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

com.unity.shadergraph/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4141
- Fixed a bug where property deduplication was failing and spamming errors [1317809] (https://issuetracker.unity3d.com/issues/console-error-when-adding-a-sample-texture-operator-when-a-sampler-state-property-is-present-in-blackboard)
4242
- Fixed a bug where synchronously compiling an unencountered shader variant for preview was causing long delays in graph updates [1323744]
4343
- Fixed a regression where custom function node file-included functions could not access shadergraph properties [1322467]
44+
- Fixed an unhelpful error message when custom function nodes didn't have a valid file [1323493].
4445

4546

4647
## [11.0.0] - 2020-10-21

com.unity.shadergraph/Editor/Data/Nodes/Utility/CustomFunctionNode.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,16 @@ public void GetSourceAssetDependencies(AssetCollection assetCollection)
5151
}
5252
}
5353

54+
enum SourceFileStatus
55+
{
56+
Empty, // No File specified
57+
DoesNotExist, // Either file doesn't exist (empty name) or guid points to a non-existant file
58+
Invalid, // File exists but isn't of a valid type (such as wrong extension)
59+
Valid
60+
};
5461
public static string[] s_ValidExtensions = { ".hlsl", ".cginc" };
5562
const string k_InvalidFileType = "Source file is not a valid file type. Valid file extensions are .hlsl and .cginc";
63+
const string k_MissingFile = "Source file does not exist. A valid .hlsl or .cginc file must be referenced";
5664
const string k_MissingOutputSlot = "A Custom Function Node must have at least one output slot";
5765

5866
public CustomFunctionNode()
@@ -385,26 +393,37 @@ void ValidateBareTextureSlots()
385393

386394
public override void ValidateNode()
387395
{
396+
bool hasAnyOutputs = this.GetOutputSlots<MaterialSlot>().Any();
388397
if (sourceType == HlslSourceType.File)
389398
{
399+
SourceFileStatus fileStatus = SourceFileStatus.Empty;
390400
if (!string.IsNullOrEmpty(functionSource))
391401
{
392402
string path = AssetDatabase.GUIDToAssetPath(functionSource);
393-
if (!string.IsNullOrEmpty(path))
403+
if (!string.IsNullOrEmpty(path) && AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(path) != null)
394404
{
395405
string extension = path.Substring(path.LastIndexOf('.'));
396406
if (!s_ValidExtensions.Contains(extension))
397407
{
398-
owner.AddValidationError(objectId, k_InvalidFileType, ShaderCompilerMessageSeverity.Error);
408+
fileStatus = SourceFileStatus.Invalid;
399409
}
400410
else
401411
{
402-
owner.ClearErrorsForNode(this);
412+
fileStatus = SourceFileStatus.Valid;
403413
}
404414
}
415+
else
416+
fileStatus = SourceFileStatus.DoesNotExist;
405417
}
418+
419+
if (fileStatus == SourceFileStatus.DoesNotExist || (fileStatus == SourceFileStatus.Empty && hasAnyOutputs))
420+
owner.AddValidationError(objectId, k_MissingFile, ShaderCompilerMessageSeverity.Error);
421+
else if (fileStatus == SourceFileStatus.Invalid)
422+
owner.AddValidationError(objectId, k_InvalidFileType, ShaderCompilerMessageSeverity.Error);
423+
else if (fileStatus == SourceFileStatus.Valid)
424+
owner.ClearErrorsForNode(this);
406425
}
407-
if (!this.GetOutputSlots<MaterialSlot>().Any())
426+
if (!hasAnyOutputs)
408427
{
409428
owner.AddValidationError(objectId, k_MissingOutputSlot, ShaderCompilerMessageSeverity.Warning);
410429
}

0 commit comments

Comments
 (0)