Subtree Reference Lost on Prefab

NodeCanvas Forums Support Subtree Reference Lost on Prefab

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #10075

    Hello there. I recently got Node Canvas and my first impressions are really good. The Interfaces for creating custom Tasks are very easily understandable 🙂

    I do have a problem however with Subtrees on a Prefab.

    I want to define some behavior in a subtree to re-use across different npc types.

    The npc’s are saved as prefabs for easy instantiation. So I have a Subtree with some behaviour created in a BT of NPC A. I save that NPC A as a prefab, instantiate it. No problem, the subtree is there.
    Now I create another NPC B, also with a BT and add a Subtree Node in that Graph. For that Subtree Node I choose the existing Subtree that I initially created on NPC A. It works fine as long as I don’t create a Prefab of NPC B. If I create a Prefab of NPC B and drag it into the scene to create an Instance, the Subtree Node is now empty. The reference I set to the Subtree is missing, the Button CREATE NEW shows.

    Do you have any idea what the problem is?

    I’m on a Mac by the way.

    Regards

    Michel

    #10076
    Gavalakis
    Keymaster

    Hello and thanks 🙂

    The problem you are facing is the fact that Unity does not serialize references from the scene. So (if I understoon correctly), you have your NPC B in the scene, drag the NPC A subtree from the scene and then make a prefab of NPC B. As a result, prefab NPC B is referencing a scene Object, which Unity can’t store. (Instantiating NPC A works, because the SubTree object is within the prefab of NPC A)

    What you would want to do is to either reference prefabs in the scene, or reference prefabs in prefabs.
    So here is a workflow:

    SubTrees are just another tree. You can create a standalone tree through “Window/NodeCanvas/Create Behaviour Tree” Unity top menu.

    Create NPC A (BehaviourTreeOwner).
    Add SubTree node and assign the previously created standalone subtree.
    Edit as you please.
    Make a prefab of the SubTree, and delete it from the scene.
    Now assign the new prefab SubTree to the SubTree Node.

    Make NPC B (BehaviourTreeOwner)
    Do the same as NPC A (create SubTree node, and assign the prefab SubTree)

    So in the end you will have 3 prefabs. NPC A, NPC B, and SubTree.
    Now instantiating the NPCs will keep the references to the subtree, which will be instantiated automaticaly for each NPC when nescessary in runtime.

    The worfklow will be much easier in the next version, where I will enable the ability to view/edit prefab trees, which right now being impossible is a bit of a pain when working with prefabs.

    Cheers. Let me know if this works for you 🙂

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

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