Skip to content

Commit e05e780

Browse files
svc-reach-platform-supportEvergreen
authored andcommitted
[Port] [6000.1] [Fix][VFX] Prevent some useless VFX recompilation/reimport in some cases
1 parent 51f8eb9 commit e05e780

File tree

3 files changed

+19
-94
lines changed

3 files changed

+19
-94
lines changed

Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/VFXConvertSubgraph.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ public void ConvertToSubgraphContext(VFXView sourceView, IEnumerable<Controller>
248248
TransferEdges();
249249
//TransferContextsFlowEdges();
250250
UninitSmart();
251+
252+
m_TargetSubgraph.GetResource()?.WriteAssetWithSubAssets();
251253
}
252254

253255
public void ConvertToSubgraphOperator(VFXView sourceView, IEnumerable<Controller> controllers, Rect rect, string path)
@@ -282,6 +284,8 @@ public void ConvertToSubgraphOperator(VFXView sourceView, IEnumerable<Controller
282284
var subGraphOperator = m_SourceNode as VFXSubgraphOperator;
283285
subGraphOperator.RecreateCopy();
284286
subGraphOperator.ResyncSlots(true);
287+
288+
m_TargetSubgraph.GetResource()?.WriteAssetWithSubAssets();
285289
}
286290

287291
List<VFXBlockController> m_SourceBlockControllers;
@@ -374,6 +378,8 @@ public void ConvertToSubgraphBlock(VFXView sourceView, IEnumerable<Controller> c
374378
TransferEdges();
375379
m_SourceControllers = m_SourceControllersWithBlocks.ToList();
376380
UninitSmart();
381+
382+
m_TargetSubgraph.GetResource()?.WriteAssetWithSubAssets();
377383
}
378384

379385
bool CreateUniqueSubgraph(string typeName, string extension, Func<string, VisualEffectObject> createFunc)

Packages/com.unity.visualeffectgraph/Editor/GraphView/Views/VFXView.cs

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,27 +1812,7 @@ internal void OnSave()
18121812
{
18131813
m_ComponentBoard?.DeactivateBoundsRecordingIfNeeded(); //Avoids saving the graph with unnecessary bounds computations
18141814

1815-
var graphToSave = new HashSet<VFXGraph>();
1816-
GetGraphsRecursively(controller.graph, graphToSave);
1817-
foreach (var graph in graphToSave)
1818-
{
1819-
if (EditorUtility.IsDirty(graph) || UnityEngine.Object.ReferenceEquals(graph, controller.graph))
1820-
{
1821-
graph.UpdateSubAssets();
1822-
try
1823-
{
1824-
VFXGraph.compilingInEditMode = !m_IsRuntimeMode;
1825-
graph.visualEffectResource.WriteAsset();
1826-
}
1827-
finally
1828-
{
1829-
VFXGraph.compilingInEditMode = false;
1830-
}
1831-
}
1832-
}
1833-
1834-
// Only for testing purpose
1835-
//VFXAnalytics.GetInstance().OnSaveVFXAsset(this);
1815+
controller.graph.visualEffectResource.WriteAssetWithSubAssets();
18361816
}
18371817

18381818
internal void SaveAs(string newPath)
@@ -1848,46 +1828,6 @@ internal void SaveAs(string newPath)
18481828
}
18491829
}
18501830

1851-
void GetGraphsRecursively(VFXGraph start, HashSet<VFXGraph> graphs)
1852-
{
1853-
if (graphs.Contains(start))
1854-
return;
1855-
graphs.Add(start);
1856-
foreach (var child in start.children)
1857-
{
1858-
if (child is VFXSubgraphOperator ope)
1859-
{
1860-
if (ope.subgraph != null)
1861-
{
1862-
var graph = ope.subgraph.GetResource().GetOrCreateGraph();
1863-
GetGraphsRecursively(graph, graphs);
1864-
}
1865-
}
1866-
else if (child is VFXSubgraphContext subCtx)
1867-
{
1868-
if (subCtx.subgraph != null)
1869-
{
1870-
var graph = subCtx.subgraph.GetResource().GetOrCreateGraph();
1871-
GetGraphsRecursively(graph, graphs);
1872-
}
1873-
}
1874-
else if (child is VFXContext ctx)
1875-
{
1876-
foreach (var block in ctx.children.Cast<VFXBlock>())
1877-
{
1878-
if (block is VFXSubgraphBlock subBlock)
1879-
{
1880-
if (subBlock.subgraph != null)
1881-
{
1882-
var graph = subBlock.subgraph.GetResource().GetOrCreateGraph();
1883-
GetGraphsRecursively(graph, graphs);
1884-
}
1885-
}
1886-
}
1887-
}
1888-
}
1889-
}
1890-
18911831
public EventPropagation OnCompile()
18921832
{
18931833
Compile();

Packages/com.unity.visualeffectgraph/Editor/Models/VFXGraph.cs

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -374,19 +374,7 @@ static string[] OnWillSaveAssets(string[] paths)
374374
AssetDatabase.StartAssetEditing();
375375
}
376376
var vfxResource = VisualEffectResource.GetResourceAtPath(path);
377-
if (vfxResource != null)
378-
{
379-
vfxResource.GetOrCreateGraph().UpdateSubAssets();
380-
try
381-
{
382-
VFXGraph.compilingInEditMode = vfxResource.GetOrCreateGraph().GetCompilationMode() == VFXCompilationMode.Edition;
383-
vfxResource.WriteAsset(); // write asset as the AssetDatabase won't do it.
384-
}
385-
finally
386-
{
387-
VFXGraph.compilingInEditMode = false;
388-
}
389-
}
377+
vfxResource?.WriteAssetWithSubAssets();
390378
}
391379
}
392380
finally
@@ -432,6 +420,13 @@ public static void UpdateSubAssets(this VisualEffectResource resource)
432420
resource.GetOrCreateGraph().UpdateSubAssets();
433421
}
434422

423+
public static void WriteAssetWithSubAssets(this VisualEffectResource resource)
424+
{
425+
var graph = resource.GetOrCreateGraph();
426+
graph.UpdateSubAssets();
427+
resource.WriteAsset();
428+
}
429+
435430
public static bool IsAssetEditable(this VisualEffectResource resource)
436431
{
437432
return AssetDatabase.IsOpenForEdit((UnityEngine.Object)resource.asset ?? resource.subgraph, StatusQueryOptions.UseCachedIfPossible);
@@ -488,15 +483,6 @@ class VFXGraph : VFXModel
488483
// 18: Change ProbabilitySampling m_IntegratedRandomDeprecated changed to m_Mode
489484
public static readonly int CurrentVersion = 18;
490485

491-
[NonSerialized]
492-
internal static bool compilingInEditMode = false;
493-
494-
public override void OnEnable()
495-
{
496-
base.OnEnable();
497-
m_ExpressionGraphDirty = true;
498-
}
499-
500486
public override void OnSRPChanged()
501487
{
502488
m_GraphSanitized = false;
@@ -1139,7 +1125,7 @@ public uint FindReducedExpressionIndexFromSlotCPU(VFXSlot slot)
11391125

11401126
public void SetCompilationMode(VFXCompilationMode mode, bool reimport = true)
11411127
{
1142-
if (m_CompilationMode != mode)
1128+
if (m_CompilationMode != mode && !GetResource().isSubgraph)
11431129
{
11441130
m_CompilationMode = mode;
11451131
SetExpressionGraphDirty();
@@ -1400,11 +1386,10 @@ public void SanitizeForImport()
14001386

14011387
public void CompileForImport()
14021388
{
1403-
if (compilingInEditMode)
1404-
m_CompilationMode = VFXCompilationMode.Edition;
1389+
bool isSubgraph = GetResource().isSubgraph;
14051390

14061391
SyncCustomAttributes();
1407-
if (!GetResource().isSubgraph)
1392+
if (!isSubgraph)
14081393
{
14091394
// Check Graph Before Import can be needed to synchronize modified shaderGraph
14101395
foreach (var child in children)
@@ -1492,21 +1477,15 @@ private VFXGraphCompiledData compiledData
14921477
[SerializeField]
14931478
private int m_ResourceVersion;
14941479

1495-
[NonSerialized]
14961480
private bool m_GraphSanitized = false;
1497-
[NonSerialized]
14981481
private bool m_ExpressionGraphDirty = true;
1499-
[NonSerialized]
15001482
private bool m_ExpressionValuesDirty = true;
1501-
[NonSerialized]
15021483
private bool m_DependentDirty = true;
1503-
[NonSerialized]
15041484
private bool m_MaterialsDirty = false;
1505-
[NonSerialized]
15061485
private bool m_CustomAttributesDirty = false;
15071486

1508-
[NonSerialized]
15091487
private VFXGraphCompiledData m_CompiledData;
1488+
15101489
private VFXCompilationMode m_CompilationMode = VFXCompilationMode.Runtime;
15111490
private bool m_ForceShaderDebugSymbols = false;
15121491
private bool m_ForceShaderValidation = false;

0 commit comments

Comments
 (0)