I’ve not been able to see a pattern with when this happens but what I can say is that its sporadic. Perhaps a race condition somewhere with how things are initialized? Usually once its happened once it will happen every time I enter playmode after that and the only way for it to go away is if I re-save the Behavior graph.
I looked around the code this morning & what it seems to look like is somehow an empty graph in the graphs list somehow. Possibly due to being deleted & not cleaned up correctly somehow but I am not sure about that yet.
The next time you see it happen, could you take a look at the debug view of the runtime graph (Second in the hierarchy) & check what is inside the Graphs list, I suspect somehow there is an empty object inside. This list shows all graphs or subgraphs that are used by the asset.
Thanks for looking into this one too so quickly @Darren_Kelly
Next time it pops up, I’ll take a look and see if there is an empty object in the graphs list.
Hey @Darren_Kelly - so it happened again (1.0.6). At the point that I am getting the error, the BehaviorGraphAgent component hasn’t actually been enabled yet, this is the code I am running to setup the graph, note that CreatureDefinition is a ScriptableObject which references the graph to use.
However, after trying, then the Runtime Graph inspector (in debug mode) showed me this stuff but I guess its not accurate because the BehaviorGraphAgent component was enabled / initialized?
Darren is off for the week and we the team is also doing a validation week this week, so we won’t be able to make much progress on that side.
However, I know we have started to rework BlackboardGraphAgent.Init for another related task. The next version might have a fix for it. It should land mind December.
Just for context in regards to the on-going changes:
Currently, Init is responsible to duplicate the graph instance and initializing the blackboard fields and you need to call it manually when spawning manually a before agent.
We are improving the BehaviorGraphAgent for it auto-initialized at the first Update frame.
That will not solve the underlying issue you are experiencing thought, as it seems to be related to asset corruption somehow (if your graph modules becomes null)… but maybe delaying the initialization to the first Update might be able to solve the issue hard to tell from the thread only.
Could you open a bug report and provide us with a minimal repro project? That would help a lot!
Hmm so the place I called .Init() from is not from an Update() - it comes quite late in the game start-up process, several seconds after the game has spun up.
Regarding a bug report, the main issue here is that it happens sporadically and I haven’t been able to figure out what exactly causes it. But when its happened, its corrupted forever until I open the graphs and re-save them. It’s currently in a corrupted state so I could check something else if you need before I go in and re-save them?
Could it be there’s still somewhere that might be calling Start before Init is called? As mentioned, we’re working to improve this, but if you’re assigning an existing graph and Start is called before Init then there is risk for the original graph asset to be modified.
@ShaneeNishryBehaviorGraphAgent.Start()? Not from my code. The component is disabled on the prefab by default and there is only the 3 lines of code I pasted above that enables it after I call Init().
Perhaps unrelated, but worth mentioning, is that multiple instances of that prefab can be spawned at once when the game starts. However, I just tested spawning 3 at once now and it didn’t cause the error to happen again but due its very sporadic nature i’m not sure if there is a race condition or something?
I am back from holiday now and can hopefully assist if you are still experiencing these issues.
If you manage to repro, even if you provide the project in the broken state it may be able to help me pinpoint what went wrong so feel free to provide one in the broken state if you can.
Right now I cannot find a solution easily from the above yet.
We are also working on re-working the Init / start flow soon to make it easier and more straight forward for user’s so that you don’t need to handle these cases yourself & we will handle them internally. Maybe this could help as well.
That’s really strange! Looking at the code I don’t think there should be any race condition happening.
That said, @davidlovegrove is working on a change to make this API more stable and easier to use avoiding the init to manually call Init or Start when assigning a graph dynamically. We’re hoping to land this in 1.0.7.
Is it possible that the error I see at runtime in my original post could be caused by something “breaking” the graph at edit-time? Instead of it specifically being an issue with the way that I call .Init()?
Because when I get this error once, it happens every time I go into playmode until I hit CTRL-S on the graphs and then it will go away.