Is there a way to assign the agent at runtime?

NodeCanvas Forums General Discussion Is there a way to assign the agent at runtime?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #9074
    alic
    Participant

    I think I’m missing something obvious here, so apologies in advance. I’m using the approach in your documentation (in the Runtime Instantiation and Tips section) to instantiate behaviour tree owners and assign behaviour trees from prefabs at runtime. When using this approach, is there a way to assign the agent once and have it stay that way? Everything I’ve tried has resulted in the agent being null. Do I have to use blackboards/override for this? And will they be assigning the agent every frame? Thanks!

    #9077
    Gavalakis
    Keymaster

    Hello,

    I’ve just re-checked the scripts found into that documentation section and seem to work fine.
    Can you please clarify what you mean that the agent is becoming null?
    When you call StartBehaviour(Graph bt) on BehaviourTreeOwner, the agent for the behaviour tree is assigned once and doesn’t become null later on.
    Could it be that you have a task in your behaviour tree that requires a component of which the agent gameobject (BehaviourTreeOwner gameobject) doesn’t have and thus you get the Task Init error stating that it “Failed to change Agent to type x, for Task y or new Agent is NULL. Does the Agent has that Component?”?

    Thanks. Please let me know.

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

    #9076
    alic
    Participant

    Hey, my bad for not mentioning the key point! I was up a little too late when I posted. Sorry to waste some of your time 🙁 I’m using Tick() on the tree owner and not using StartBehavior(). That’s the code from the documentation I was using (I’m using the behavior trees for a turn-based game, so tick makes sense.) I figured out I could get it to work by calling StartBehavior() and EndBehavior(), and get exactly the behaviour I want with the lines

    before I start ticking the tree owner. It doesn’t work with the code in the documentation as far as I can tell, though.

    #9075
    Gavalakis
    Keymaster

    Hello,

    No problem at all! 🙂

    You are correct that there is a bug there. I will fix it in the next version update. It’s not an easy one to post here unfortunately.

    By the way, if you are after a turn-based behaviour, setting runForver to false and starting the behaviour with StartBehaviour is probably the best way to go (without stopping it manualy).
    By doing this, the behaviour will run once and stop when it’s finished (meaning no action is Running and the root status is either Success or Failure).
    You can even provide a callback when starting the behaviour with overload StartBehaviour(System.Action callback), which will be called once it’s finished, so that you can possibly proceed to the next unit for example or “chain” other things.

    Let me know if you need any further help with that and if it satisfies your needs.

    Thanks

    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.