Search Unity

Change Agent Size via Script?

Discussion in 'Navigation' started by GainfulSage, May 17, 2019.

  1. GainfulSage

    GainfulSage

    Joined:
    Apr 30, 2015
    Posts:
    106
    I have a number of GameObjects of different size, with colliders attached - either a single sphere or cylinder. I'd like to be able to set the agent size programmatically, instead of creating a lot of different agents in the UI. Ideally, just copying the collider size directly over to the agent. Is this possible? Any suggestions about how to approach?

    I get that the agents are round, so I'll likely be using either the sphere directly or the full length of the cylinder.

    Mostly I just want to know if this is remotely feasible, or if I should just create a set of agents in the editor as best approximations.
     
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Agent Types are always shared, so if you were to change the size of one you'd change it for all agents using the same type. Keep in mind that agent settings are mostly used for baking and avoidance, so unless you want to affect avoidance you're not doing much either way without triggering a rebake.
     
  3. GainfulSage

    GainfulSage

    Joined:
    Apr 30, 2015
    Posts:
    106
    Actually, avoidance is exactly what I'm looking at. I think I figured things out. I'm changing the avoidance to match the size of the collider and it's working nicely.

    Thanks!