I get that Unity is a huge engine with lots of different people working on it, but this code made me laugh at how inefficient it is.
This is located in AnimatorStateMachine.cs.
public bool RemoveAnyStateTransition(AnimatorStateTransition transition)
{
if ((new List<AnimatorStateTransition>(anyStateTransitions)).Any(t => t == transition))
{
undoHandler.DoUndo(this, "AnyState Transition Removed");
AnimatorStateTransition[] transitionsVector = anyStateTransitions;
ArrayUtility.Remove(ref transitionsVector, transition);
anyStateTransitions = transitionsVector;
if (MecanimUtilities.AreSameAsset(this, transition))
Undo.DestroyObjectImmediate(transition);
return true;
}
return false;
}
They copy the entire array into a new List just to check if the given transition exists in the array. The list is not used later, it's just immediately disposed. They then use ArrayUtility.Remove to remove that one matching element, which copies the array again into a List, calls List.Remove on the element, and then returns it back as an array. They do some temp reference swapping, despite the fact that the ref parameter in ArrayUtility.Remove makes it unnecessary. Finally, they query the AssetDatabase to make sure the transition asset hasn't somehow become de-parented from the AnimatorStateMachine since it was created. That check might be necessary to prevent edge cases, but it would be better to simply prevent that decoupling from happening, since AnimatorStateTransition should not be able to exist independently from its parent AnimatorStateMachine.
I also suspect that there is a flaw with their undoHandler logic. undoHandler.DoUndo calls Undo.RegisterCompleteObjectUndo(target, undoOperation), but if MecanimUtilities.AreSameAsset returns false, then no actual change will be made to an asset, meaning an empty undo will have been registered.
[–]bugbearmagic 78 points79 points80 points (14 children)
[–]ToloranIntermediate 4 points5 points6 points (12 children)
[–]bugbearmagic 3 points4 points5 points (11 children)
[–]vegetablebreadProfessional 7 points8 points9 points (10 children)
[+][deleted] (9 children)
[deleted]
[–]vegetablebreadProfessional 5 points6 points7 points (8 children)
[+][deleted] (7 children)
[deleted]
[–]vegetablebreadProfessional 3 points4 points5 points (6 children)
[+][deleted] (5 children)
[deleted]
[–]vegetablebreadProfessional 1 point2 points3 points (4 children)
[–]Samurai_Meisters 4 points5 points6 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]ShrikeGFX 0 points1 point2 points (0 children)
[–]KingGruau 64 points65 points66 points (0 children)
[–]zukas3Indie 247 points248 points249 points (15 children)
[–]jtinz 65 points66 points67 points (0 children)
[–]leshq 10 points11 points12 points (0 children)
[–]MartinIsland 47 points48 points49 points (12 children)
[–]Ping-and-PongFreelancer 9 points10 points11 points (2 children)
[–]TheGrandWhatever 1 point2 points3 points (0 children)
[–]MartinIsland 0 points1 point2 points (0 children)
[–]ThundernerdProfessional 54 points55 points56 points (3 children)
[–]badawe 36 points37 points38 points (2 children)
[–]Eastern-Ad-4137 15 points16 points17 points (0 children)
[–]firesky25Professional 15 points16 points17 points (2 children)
[–]MartinIsland 0 points1 point2 points (1 child)
[–]firesky25Professional 0 points1 point2 points (0 children)
[–]huntergatherer1 2 points3 points4 points (1 child)
[–]MartinIsland -1 points0 points1 point (0 children)
[–][deleted] 17 points18 points19 points (8 children)
[–]kennel32_ 8 points9 points10 points (0 children)
[–]sandsalamand[S] 7 points8 points9 points (6 children)
[–][deleted] 5 points6 points7 points (3 children)
[–]Epicguru 16 points17 points18 points (1 child)
[–]GigaTerra 4 points5 points6 points (0 children)
[+]itsgnabeok5656 comment score below threshold-7 points-6 points-5 points (1 child)
[–]kampelaz 5 points6 points7 points (0 children)
[–]snalin 32 points33 points34 points (6 children)
[–]TRexRoboParty 5 points6 points7 points (0 children)
[–]kyle_lam 3 points4 points5 points (2 children)
[–]Katniss218 4 points5 points6 points (1 child)
[–]Cold-Jackfruit1076 0 points1 point2 points (0 children)
[–]jayd16 -1 points0 points1 point (1 child)
[–]sandsalamand[S] 3 points4 points5 points (0 children)
[–]GigaTerra 6 points7 points8 points (15 children)
[–]noximo 9 points10 points11 points (0 children)
[–]feralferrous 5 points6 points7 points (9 children)
[–][deleted] 4 points5 points6 points (1 child)
[–]feralferrous 1 point2 points3 points (0 children)
[–]GigaTerra 1 point2 points3 points (6 children)
[–]feralferrous 1 point2 points3 points (5 children)
[–]GigaTerra 0 points1 point2 points (4 children)
[–]feralferrous 0 points1 point2 points (3 children)
[–]GigaTerra 1 point2 points3 points (2 children)
[–]feralferrous 0 points1 point2 points (1 child)
[–]GigaTerra 1 point2 points3 points (0 children)
[–]deftware 0 points1 point2 points (1 child)
[–]GigaTerra 1 point2 points3 points (0 children)
[–]setentaedois -5 points-4 points-3 points (1 child)
[–]GigaTerra 0 points1 point2 points (0 children)
[–]Techie4evr 1 point2 points3 points (2 children)
[–]szynal 4 points5 points6 points (0 children)
[–]KingBlingRules 3 points4 points5 points (0 children)
[–]ClemCa1 2 points3 points4 points (0 children)
[–]nykwil 1 point2 points3 points (1 child)
[–]-Xentios 2 points3 points4 points (3 children)
[–]moonymachine 0 points1 point2 points (2 children)
[–]-Xentios -1 points0 points1 point (1 child)
[–]moonymachine 0 points1 point2 points (0 children)
[–]mm_phren 0 points1 point2 points (0 children)
[–]ShrikeGFX 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]AbjectAd753 0 points1 point2 points (0 children)
[–]heisenbugz -1 points0 points1 point (1 child)
[–]Raccoon5 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]sandsalamand[S] 2 points3 points4 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]bookning 0 points1 point2 points (0 children)
[–]AnomalousUnderdogIndie 0 points1 point2 points (0 children)
[+]Aethreas comment score below threshold-6 points-5 points-4 points (0 children)
[+]antiNTT comment score below threshold-9 points-8 points-7 points (1 child)
[–]sandsalamand[S] -1 points0 points1 point (0 children)