Flock agents SetVariableValue string name?

jimi

Member
Hi there,

I was wondering how to set the agents of the NavMeshGroupMovement movements like flock at runtime.

I have a list of game objects I've tried to set like this:
C#:
FlockTree.SetVariableValue("agents", Boars);
But, Error: No variable exists with name Agents or agents.

I've also tried creating a new variable and exposing like this:

Untitled1.jpg


but not sure how to link it to the Agents list. Any guidance would be appreciated, thanks.
 
In your behavior tree you'll need to create a new SharedGameObject[] and then within the Flock task assign that variable by clicking on the little dot to the right of the agents field. From there you'll be able to set a reference to it with SetVariableValue.
 
Ok, Thanks Justin. I don't quite follow.

What do you mean by create a new SharedGameObject[] in the tree? Like this?:

Untitled2.jpg

I am able to populate this list ok. But don't see how to assign that to the Agents array itself. There is no little dot for the whole array, only each element.

So I tried creating one element with the dynamic string "BoarsAgents" like this:
Untitled3.jpg

but getting: Error: No variable exists with name BoarsAgents with
C#:
            Boars.Add(instance);
        }
        FlockTree.SetVariableValue("BoarsAgents", Boars);

So I tried using the Set Game Object List task like this:

1606079146986.png

But getting a type mismatch.

Do I have to have a predetermined Agents array size before hand and set each element individually like BoarAgent1, BoarAgent2 etc? It is preferred to stay flexible so I can have a varying amount of agents.
 
I am able to populate this list ok. But don't see how to assign that to the Agents array itself. There is no little dot for the whole array, only each element.

So I tried creating one element with the dynamic string "BoarsAgents" like this:
That is correct, but you are assigning a GameObjectList to a GameObject[] so the dot won't show you the Bores list that you created. I see the problem now. Behavior Designer doesn't include a GameObject[] SharedVariable so for your situation I would modify the flock task so it uses a SharedGameObjectList instead of SharedGameObject[].
 
Awsome, thank you Justin. Perfect solution. For anyone that stumbles upon this
C#:
public SharedGameObject[] agents = null;

agents.Length
agents[i].Value.transform

//changes to
public SharedGameObjectList agents = null;

agents.Value.Count
agents.Value[i].transform
//etc
 
Top