Skip to content

Commit 138f74e

Browse files
committed
Fix for unuseful error
1 parent 112cd8a commit 138f74e

6 files changed

Lines changed: 20 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [0.6.5-beta] - Aug 16, 2024
44
- Updated frame delay of DelayState transition to 0
5+
- Fix for add nodes multiple times when entering runtime
6+
- Fix for unuseful error thrown when sub state-machines ref is missing
57

68
## [0.6.4-beta] - Aug 12, 2024
79
- Fix for rogue tilda

Editor/NodeGraph/NodeGraphStateManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public virtual void SaveState()
7777

7878
public void SetModel(NodeGraphDataModel model)
7979
{
80+
if (!model) return;
81+
8082
Model = model;
8183
SaveState();
8284
}

Editor/NodeGraph/NodeGraphView.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ public NodeGraphView(string id)
3333

3434
public virtual void PopulateGraph(NodeGraphDataModel model)
3535
{
36-
if (!model) return;
37-
3836
StateManager.SetModel(model);
3937
ClearGraph();
4038
}
@@ -117,7 +115,7 @@ private void HandleModelChanged(NodeGraphDataModel model)
117115
PopulateGraph(model);
118116
}
119117

120-
private void ClearGraph()
118+
protected virtual void ClearGraph()
121119
{
122120
DeleteElements(graphElements);
123121
}

Editor/StateGraph/VisualElements/StateGraphView.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,17 @@ public void PopulateGraph(NodeGraphDataModel model, bool recentre)
4848
_toolBar.SetModel(stateModel);
4949
_footerBar.SetGridPosition(StateManager.GridPosition);
5050
_footerBar.SetModel(stateModel);
51-
51+
5252
base.PopulateGraph(model);
5353
AddEntryNode(stateModel);
5454

55+
//A delay is required to allow the entry node time to be added
5556
EditorApplication.delayCall += () =>
5657
{
58+
//It's possible that the delayCall is invoked multiple times when entering run time
59+
//This just prevents adding the nodes multiple times
60+
if (nodes.ToList().Count > 0) return;
61+
5762
AddNodes(stateModel);
5863
AddEdges(stateModel);
5964

Runtime/StateGraph/States/BaseSubStateMachineState.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,32 @@ public override void OnAwakeState()
2828

2929
public override void OnStartState()
3030
{
31-
SubStateMachine.Start();
31+
SubStateMachine?.Start();
3232
}
3333

3434
public override void OnEnterState()
3535
{
36+
if(SubStateMachine == null) return;
37+
3638
SubStateMachine.Model.SetParent(SubStateMachine.Model);
3739
SubStateMachine.OnComplete += OnSubStateComplete;
3840
SubStateMachine.Enter();
3941
}
4042

4143
public override void OnUpdateState()
4244
{
43-
SubStateMachine.Update();
45+
SubStateMachine?.Update();
4446
}
4547

4648
public override void OnFixedUpdateState()
4749
{
48-
SubStateMachine.FixedUpdate();
50+
SubStateMachine?.FixedUpdate();
4951
}
5052

5153
public override void OnExitState()
5254
{
55+
if(SubStateMachine == null) return;
56+
5357
SubStateMachine.OnComplete -= OnSubStateComplete;
5458
SubStateMachine.Exit();
5559
}
@@ -58,7 +62,7 @@ public override void OnDestroyState()
5862
{
5963
ReplaceModelWithOriginalModel();
6064

61-
SubStateMachine.OnDestroy();
65+
SubStateMachine?.OnDestroy();
6266
}
6367

6468
protected virtual void CreateStateMachine()

Runtime/StateGraph/States/SubStateMachineState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Nonatomic.VSM2.StateGraph.States
55
{
66
public class SubStateMachineState : BaseSubStateMachineState
77
{
8-
[Transition]
8+
[Transition(frameDelay:0)]
99
public event Action OnComplete;
1010

1111
protected override void OnSubStateComplete(State state, StateMachineModel model)

0 commit comments

Comments
 (0)