public static ReGoapState <T, W> Instantiate(ReGoapState <T, W> old = null) { if (cachedStates == null) { cachedStates = new Stack <ReGoapState <T, W> >(); } ReGoapState <T, W> state = cachedStates.Count > 0 ? cachedStates.Pop() : new ReGoapState <T, W>(); state.Init(old); return(state); }