How do I dynamically load dialog trees from prefabs?

NodeCanvas Forums General Discussion How do I dynamically load dialog trees from prefabs?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #14216
    toreth
    Participant

    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.

    #14223
    Gavalakis
    Keymaster

    Hello and welcome 🙂

    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.

    Let me know if that works for you.

    Thanks 🙂

    Join us on Discord: https://discord.gg/97q2Rjh

    Attachments:
    You must be logged in to view attached files.
    #14234
    toreth
    Participant

    That works perfectly.  Thanks so much for making that change.

    #14248
    Gavalakis
    Keymaster

    You are very welcome 🙂
    Thanks for letting me know. This change will exist in the next version update by the way 🙂

    Join us on Discord: https://discord.gg/97q2Rjh

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.