Forums › 💬 NodeCanvas › ⚙️ Support › Transition not executing
Hi there,
I’ve been having a consistent problem with my transitions on the state machine. Basically I have it set up so that on the main node, I’ll run an action to determine what kind of state the AI should be in (idling, roaming, playing, going to the hotel etc). The check will set a string called idleAction to whatever it needs to do (hotel for going to the hotel, idle for idling, roam for roaming around etc).
But in some cases, even after setting the string to the correct value, it won’t transition from the main node at all; instead it will just execute it again, get a different value for idleAction, and execute that instead.
I’ve annexed an image of the current setup. Is there something I’m doing wrong?
Hello,
Hmm. I can’t see something immediately wrong from your image.
For the state to be executed again once it’s finished, it really either has to be set to “Repeat State Actions” (which is not in your case), or somehow has it be re-entered from another state. I can see some incoming transitions to the “Idle” state. Are you sure that none of these transitions may come from some “Any State” node and thus force the “Idle” state to re-start.
Can you please alss try setting the transition mode of the “Idle” state to “Check Continously” instead of “Check After State Finished” just to check things and let me know if it works in that mode?
Thank you.
Hey,
So there’s no direct connection from an “Any State” to the “Idle” state. I do use two “Any State” nodes; one of which is completely independent, the other of which you can see on the image, eventually goes back to Idle through other nodes.
Setting it to “Check Continuously” does make the states transition correctly. If I understood its concept, it’ll check at every frame/tick if any of the conditions coming out of it will trigger, correct? If so, when reentering that node, I’d have to reset idleAction to empty or something so that the node actually activates before moving outside of it, right?
Hello again,
Yes, that is correct. If a state’s transitions mode is set to “Check Continously” it will check all transition condition per-frame while the state is active. Thus you are also correct that when that is the case, you should probably also reset the “idleAction” to empty so that a transition is not made immediately.
There is however a window of 1 frame before transitions are checked. This means that you can if desired, reset “idleAction” to empty within your “Idle” state, yes. Just make sure that it is the first thing you do in the state (meaning doing it in the 1st execution frame) 🙂
Let me know if that works for you.
Thanks!
Hello,
I’ve done that, and the transitions appear to be moving correctly however… Is there a chance that variables in one graph are shared between all instances?
For example, in the below graph, I have 3 AIs in the scene that use it. I’ve made a new Wait between X and Y seconds action that will randomly pick a float, and wait between that many seconds elapsed before returning true. Technically, there should be a difference in action between them; some of them would get out of their Start selector earlier than others.
In a test scenario, I had all three of them on the scene, they all decided to go Idling. Because of the Wait Between 3 and 11 Seconds node in there, two of them finished earlier than the third guy, and went back to the Start selector. So far so good!
Then, one of them finished the Idle Selector action first, which decided that he should go roaming, setting the landState to “doRoam”. All good. I could see from my debug logs that this particular guy actually ran the Idle Selector and got the result he was looking for.
But then, all of the three AIs had their landState set to “doRoam”. Only one of them executed the Idle Selector function, but all three of them transitioned into the Roam state. Obviously this is undesirable behavior, as the Idle Selector action also sets extra parameters in other scripts that can cause things to break if not set properly. Is there something I’m missing?
So far, all the variables were dynamic. I’d just name them whatever inside the graph asset, and then set them inside my actions by calling for example:
blackboard.SetValue("landState", "doBuild");
Is there some step I’m missing?
Ok, an update since I did some more investigation.
I had originally setup another AI type with its own FSMOwner and BlackBoard. For this AI type (the builder), I copied both components over to speed up the setup process, and set the FSM graph to the correct asset.
I set the owner to be bound, just to see if that had an effect. I then noticed that upon opening the bound graph, that the Graph was trying to use the Blackboard from the original AI type (a gameobject called Golfer) instead of the current owner’s blackboard (the gameobject called Builder). Therefore no matter how many variables I added to the blackboard component, they were never showing up on the graph.
I fixed this by removing both components (the graph owner and the blackboard), readding them, and then setting the graph to the asset I had made. This made the graph refer to the correct blackboard and could see the variables that were being added.
Not sure if it helps, but looks like a bug when copying components around.
Hello again,
Thank you for the detailed post.
I honestly have never encounter such a problem with copy/pasting of components or more specifically blackboard before.
I am trying to replicate this or any similar problem just now to no avail. What Unity version did this happen on?
Were any of the gameobjects in question a prefab?
I will keep looking for the possibility of a bug there.
Thanks again!
