public static new PathNNConstraint Walkable {
get {
return new PathNNConstraint {
constrainArea = true
};
}
}
This causes GC each time its called, which is every few frames by our audio occlusion logic.
public static new PathNNConstraint Walkable {
get {
return new PathNNConstraint {
constrainArea = true
};
}
}
This causes GC each time its called, which is every few frames by our audio occlusion logic.
Hi
This is hard to get away from, unfortunately.
I cannot just return the same instance every time, because NNConstraint is a class, and therefore mutable. Using the same instance would break a ton of code that people are using.
In the future, I may change the NNConstraint to be a struct instead.
Per-frame allocations are something we can’t have so perhaps there is some way to work around this? For example, could you allow us to pass through our own cached PathNNConstraint instead of you creating a new one on each call for .Walkable? Surely there is some way this can be avoided.
You could change this line in the Path.cs file’s Reset
method.
nnConstraint = PathNNConstraint.Walkable;
If you remove it, the NNConstraint will never be recreated. However, then you must ensure that you never assign a custom NNConstraint to a path, and never keep a reference to one in a path.
For most common cases, this works out of the box. But it can lead to hard to debug issues if those preconditions do not hold.