Forums › 💬 NodeCanvas › ⚙️ Support › Creating-lag of DynamicVar › Reply To: Creating-lag of DynamicVar
Hello,
I found the problem in last versions of NodeCanvas. To fix the allocations with Dynamic Variables, please open up BBParameter.cs script and change the property ‘varRef’ at line #130 to this:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
public Variable varRef{ get {return _varRef;} set { if (_varRef != value){ #if UNITY_EDITOR //this avoids lots of allocations when using Dynamic Variables if (!Application.isPlaying){ if (_varRef != null){ _varRef.onNameChanged -= OnRefNameChanged; //remove old one } if (value != null){ value.onNameChanged += OnRefNameChanged; //add new one OnRefNameChanged(value.name); //update name immediately } targetVariableID = value != null? value.ID : null; } #endif _varRef = value; Bind(value); } } } |
Then just a few lines later, please also change property ‘bb’ to this:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
///The blackboard to read/write from. Setting this also sets the variable reference if found public IBlackboard bb{ get { return _bb; } set { if (_bb != value){ #if UNITY_EDITOR //avoid when using Dyanmic Variables if (!Application.isPlaying){ if (_bb != null){ _bb.onVariableAdded -= OnBBVariableAdded; _bb.onVariableRemoved -= OnBBVariableRemoved; } if (value != null){ value.onVariableAdded += OnBBVariableAdded; value.onVariableRemoved += OnBBVariableRemoved; } } #endif _bb = value; varRef = value != null? ResolveReference(_bb, true) : null; } } } |
After this change there will be a minimal allocations caused only by the logs.
Thanks for spotting this out.
