Seeker Valid Tags change on runtime

Hi,

Could anyone share some code as to how I can change the seeker Valid Tags if a particular bool is on?

My situation is that I would like to enable/disable tags based on this bool so I can have different units without having it to do it manually.

Atm I am saving prefabs but it would be easier to just do it via code but I can’t find any ref on Unity as to how I can target a dropdown like the Valid Tags one within a script ecc…

Thanks

I’m too stuck on this problem. Do you find any solution?

Not yet mate.

I hope Aron will answer this one because it gets harder with more units to manage all.

Bumping this one as I tried almost everything. Help!?

Hi

Sorry for the late answer. This new forum software hasn’t got a good way to keep track of which topics are answered and which are not.

You can use the tagMask.tagsChange field on the Seeker (I will be changing this soon however so that you can just use tagMask). The field is a bitmask, so bit 0 indicates whether the first tag should be enabled, etc. See https://en.wikipedia.org/wiki/Mask_(computing)

// Set tags 0, 2 and 5 as the only ones that can be traversed
GetComponent<Seeker>().tagMask.tagsChange = (1 << 0) | (1 << 2) | (1 << 5);
1 Like

Brilliant, Thanks Aron!

No problem :smile:
Also, please ‘like’ the answer if it worked for you.

1 Like

Hi Aron,

It did not work for me. As it kept giving

`tagMask' and no extension method `tagMask' of type `Seeker' could be found (are you missing a using directive or an assembly reference?)

However after going over the seeker script to see why this error was showing up I found a solution and this worked.

// Set tags 0, 2 and 5 as the only ones that can be traversed
UnitSeeker.traversableTags.tagsChange = (1 << 0) | (1 << 2) | (1 << 5);

Is this method ok?

Also what should I do if I want to select every tag (“Everything”)? I am asking as I will be using the above in an if statement.

Thanks Buddy.

1 Like

Ah, yes, it seems I didn’t remember the name of the field correctly. It should be traversableTags like you figured out.

“Everything” in a bitmask is equal to the value negative one (-1). See https://en.wikipedia.org/wiki/Two’s_complement

1 Like

All clear now :smile:

What if you want to do a range that would set tags 5-10 as traversable, for example?

Hi

Setting a range is not the easiest thing when using bitmasks, however this cryptic code will do it:

int minTag = 5;
int maxTag = 10;
int bitmask = ((2 << maxTag) - 1) & ~((1 << minTag) - 1);

It might not work if maxTag = 31 though, but for all lower values of maxTag it should work.

You can of course also do

int mask = 0;
for (int i = 5; i <= 10; i++) mask |= 1 << i;