Skip to content

Commit 5d9ade0

Browse files
julienamsellemEvergreen
authored andcommitted
[VFX] Exception when deleting the whole graph
Jira: UUM-62094 How to reproduce: 1. Create a new Unity project using 3D (URP) or 3D (HDRP) Template 2. Make sure that project has Visual Effect Graph package installed 3. Create a new VFX Asset using Minimal System 4. Open VFX asset 5. In Update Particles block add/create Set Age Attribute 6. Select entire Graph and delete it 7. Observe the Console window Expected result: no errors are thrown when entire Graph is deleted Actual result: "NullReferenceException" errors are thrown when entire Graph is deleted Reproducible with: 17.0.0 (2023.3.0a7), 17.0.2 (2023.3.0b4) Not reproducible with: 17.0.0 (2023.3.0a6) Note: not reproducible with other blocks like Collision, Force, FlipBook Error: > NullReferenceException: Object reference not set to an instance of an object UnityEditor.VFX.ReadWritableAttributeProvider.GetAvailableString (UnityEditor.VFX.VFXModel model) (at ./Library/PackageCache/com.unity.visualeffectgraph/Editor/Models/Parameters/VFXAttributeParameter.cs:42) UnityEditor.VFX.UI.StringPropertyRM+<>c__DisplayClass2_2.<FindStringProvider>b__1 () (at ./Library/PackageCache/com.unity.visualeffectgraph/Editor/GraphView/Views/Properties/StringPropertyRM.cs:84) VFXSlotContainerEditor.DoInspectorGUI () (at ./Library/PackageCache/com.unity.visualeffectgraph/Editor/Inspector/VFXSlotContainerEditor.cs:59) VFXSlotContainerEditor.OnInspectorGUI () (at ./Library/PackageCache/com.unity.visualeffectgraph/Editor/Inspector/VFXSlotContainerEditor.cs:315) VFXBlockEditor.OnInspectorGUI () (at ./Library/PackageCache/com.unity.visualeffectgraph/Editor/Inspector/VFXBlockEditor.cs:23) UnityEditor.UIElements.InspectorElement+<>c__DisplayClass74_0.<CreateInspectorElementUsingIMGUI>b__0 () (at /Users/bokken/build/output/unity/unity/Editor/Mono/UIElements/Inspector/InspectorElement.cs:729) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:219)
1 parent 03116fa commit 5d9ade0

File tree

2 files changed

+36
-1
lines changed
  • Packages/com.unity.visualeffectgraph/Editor/GraphView/Views
  • Tests/SRPTests/Projects/VisualEffectGraph_HDRP/Assets/AllTests/Editor/Tests

2 files changed

+36
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,10 +1163,15 @@ void Delete(string cmd, AskUser askUser)
11631163

11641164
if (shouldClearBlackboardSelection)
11651165
{
1166-
selection.Clear();
11671166
blackboard.EmptySelection();
11681167
}
11691168

1169+
// Remove VFX items from the editor selection
1170+
var newSelection = Selection.objects.ToList();
1171+
newSelection.RemoveAll(x => x is VFXModel);
1172+
1173+
selection.Clear();
1174+
Selection.objects = newSelection.ToArray();
11701175
controller.Remove(selectionCopy.OfType<IControlledElement>().Select(t => t.controller).ToArray(), true);
11711176
}
11721177
}

Tests/SRPTests/Projects/VisualEffectGraph_HDRP/Assets/AllTests/Editor/Tests/VFXGUITests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using UnityEngine;
1212
using UnityEngine.TestTools;
1313
using Moq;
14+
using UnityEditor.Experimental.GraphView;
1415
using UnityEditor.Search;
1516
using UnityEditor.SearchService;
1617
using UnityEditor.VFX.UI;
@@ -945,6 +946,35 @@ public IEnumerator Check_ObjectPropertyRMTextureSearch()
945946
}
946947
}
947948

949+
[UnityTest, Description("Covers: UUM-61929")]
950+
public IEnumerator Check_Selection_Is_Emptied_On_Delete()
951+
{
952+
// Prepare
953+
EditorWindow.GetWindow<InspectorWindow>(); // Show the inspector because the issue was triggered by our inspector editor
954+
EditorWindow.GetWindow<ProjectBrowser>(); // Show the project browser to select asset (so that the selection is not empty)
955+
956+
var window = CreateSimpleVFXGraph();
957+
var setAgeOperatorDesc = VFXLibrary.GetBlocks().FirstOrDefault(o => o.name == "Set age");
958+
var setAgeBlock = setAgeOperatorDesc.CreateInstance();
959+
window.graphView.controller.contexts.Single(x => x.model is VFXBasicUpdate).model.AddChild(setAgeBlock);
960+
window.graphView.controller.ApplyChanges();
961+
962+
window.graphView.Focus();
963+
window.graphView.AddRangeToSelection(window.graphView
964+
.GetAllNodes()
965+
.Union(window.graphView.nodes.Where(x => x is VFXBlockUI block && block.controller.model is SetAttribute).OfType<ISelectable>())
966+
.ToList());
967+
Selection.Add(window.displayedResource.asset);
968+
Assert.IsTrue(Selection.objects?.Length > 1);
969+
970+
// Act
971+
window.graphView.Delete();
972+
yield return null;
973+
974+
// Assert
975+
Assert.IsTrue(Selection.objects?.Length == 1);
976+
}
977+
948978
private void CheckNumericPropertyRM<T,U>(Func<IPropertyRMProvider, NumericPropertyRM<T, U>> creator, UnityEngine.PropertyAttribute attribute, T initialValue, List<(T, T)> testCases)
949979
{
950980
// Arrange

0 commit comments

Comments
 (0)