Get/Set collision group in code

#1

I am trying to find a way to set a game object’s collision group dynamically on it’s init function, but I can’t find how. Isn’t it possible?

0 Likes

#2

I believe that it isn’t. Are you using a GO or Collection factory? If you want to set it in the init, can’t you just set it in the collision group’s settings?

0 Likes

#3

Currently using a go factory.

Yeah, I said that wrong, not in init, but as soon as I create it in the factory. The factory spawns objects for two different teams and I wish I could filter collisions just for the adversary. Guess I’ll have to do it via an if statement…

0 Likes

#4

Hmmmm… I can think of two things:

  • make two different GO factories if that fits your needs? One for each time?
  • you should also remember that you can get other_id in the collision table to see what object you’re colliding with. That might be helpful to you depending on your case
1 Like

#5

That’s what I am currently doing. I was trying to set the groups to avoid wasting performance on unnecessary collision checks, but oh well, that’s life. Thanks!

0 Likes

#6

This would be a good feature request!

2 Likes

#7

You can have a single game object with two different colliders and disable the one you don’t need.

4 Likes

#8

This is a possible workaround, but you need to create a collisionobject for each group you want to have (remembering about a limit - max 16 collision groups)

image

One collision object has one group and can have multiple masks - so you can specify with which groups should a certain group interact/collide.

Then you can change it in code:

msg.post("#collisionobject", "disable")
msg.post("#collisionobject", "enable")

Vote for it! [ :+1: ]

1 Like

#9

Yep, please vote for features that are important to you!

3 Likes

#10

There’s a way to sort issues by most :+1: reactions!

2 Likes