Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 0 additions & 112 deletions TestProjects/VisualEffectGraph/Assets/VFXDefaultResources.asset

This file was deleted.

This file was deleted.

35 changes: 32 additions & 3 deletions com.unity.visualeffectgraph/Editor/Models/VFXGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ namespace UnityEditor.VFX
[InitializeOnLoad]
class VFXGraphPreprocessor : AssetPostprocessor
{
void OnPreprocessAsset()
{
bool isVFX = assetPath.EndsWith(VisualEffectResource.Extension);
if (isVFX)
{
VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(assetPath);
if (resource == null)
return;

resource.GetOrCreateGraph().SanitizeForImport();
}
}

static string[] OnAddResourceDependencies(string assetPath)
{
VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(assetPath);
Expand Down Expand Up @@ -665,6 +678,24 @@ IEnumerable<VFXGraph> GetAllGraphs<T>() where T : VisualEffectObject
//Explicit compile must be used if we want to force compilation even if a dependency is needed, which me must not do on a deleted library import.
public static bool explicitCompile { get; set; } = false;


public void SanitizeForImport()
{
if (!explicitCompile)
{
HashSet<int> dependentAsset = new HashSet<int>();
GetImportDependentAssets(dependentAsset);

foreach (var instanceID in dependentAsset)
{
if (EditorUtility.InstanceIDToObject(instanceID) == null)
{
return;
}
}
}
SanitizeGraph();
}
public void CompileForImport()
{
if (!GetResource().isSubgraph)
Expand All @@ -680,13 +711,11 @@ public void CompileForImport()
{
if (EditorUtility.InstanceIDToObject(instanceID) == null)
{
//Debug.LogWarning("Refusing to compile " + AssetDatabase.GetAssetPath(this) + "because dependency is not yet loaded");
return;
}
}
}

SanitizeGraph();
// Graph must have been sanitized at this point by the VFXGraphPreprocessor.OnPreprocess
BuildSubgraphDependencies();
PrepareSubgraphs();

Expand Down
Loading