I’m new to NodeCanvas and I’m trying to figure out how to dynamically load Dialogue Trees into Finite State Machine actions. The Dialogue Tree documentation shows an example of adding the Dialogue Tree as a game object in the scene. I did that, and the dialog works. However, I want to be able to create prefabs for each Dialogue Tree, and have the “Start Dialogue” action of my FSM dynamically load the Dialogue Tree.
I thought about putting a DialogueTreeController variable on my actor’s blackboard and then dynamically assigning that value in another action, but when I try to load my Dialogue Tree prefab using the code below, LoadAssetAtPath returns null, even though the path exists.
var assetPaths = AssetDatabase.FindAssets(“My Dialog”);
var dialogTreeController = AssetDatabase.LoadAssetAtPath<GameObject>(assetPaths[0]);
What’s the correct way to go about dynamically loading dialog trees from prefabs? I don’t want to write a bunch of code to reinvent something which probably already exists.
Hmm. I have just modified the “Start Dialogue” action with an option “Is Prefab”.
When that option is enable, the assigned DialoggueTreeController will be automatically instantiated and will also automatically be destroyed when the Dialogue is finished.
I have attached the modified action for you here to test it out.