SpriteKit: why node in collision has category bit mask of 4294967295 when this category was never assigned to a node
Asked Answered
I

1

6

In the didBegin function below, one of the nodes has a category bit mask of 4294967295. However, this category is never assigned to any node.

Here are all the bit masks in use:

struct PhysicsCategory {
    static let None                 : UInt32 = 0
    static let All                  : UInt32 = UInt32.max
    static let Player               : UInt32 = 0b1       // 1
    static let WorldBorder          : UInt32 = 0b10      // 2
    static let TopWorldBorder       : UInt32 = 0b100     // 4
    static let RightWorldBorder     : UInt32 = 0b1000    // 8
    static let Pellet               : UInt32 = 0b10000
}

To repeat, the All category, which corresponds to 4294967295, is never assigned to any node. So why is there a physics body with this category bit mask? Is this category bit mask ever implicitly assigned to a physics body?

func didBegin(_ contact: SKPhysicsContact) {
    print("Collision was detected: \(contact.bodyA.categoryBitMask). \(contact.bodyB.categoryBitMask).")
}
Immortalize answered 29/11, 2016 at 5:3 Comment(0)
N
7

categoryBitMask is a UInt32 and its max value is 4294967295 which is also its default value (all bits set). Quote from docs:

Every physics body in a scene can be assigned to up to 32 different categories, each corresponding to a bit in the bit mask. You define the mask values used in your game. In conjunction with the collisionBitMask and contactTestBitMask properties, you define which physics bodies interact with each other and when your game is notified of these interactions.

The default value is 0xFFFFFFFF (all bits set).

Nonna answered 29/11, 2016 at 7:59 Comment(2)
@Immortalize No problem :) Unlike contactTestBitMask which is set to 0x00000000, collisionBitMask and categoryBitMask have all bit set. So that is a thing :)Nonna
@Immortalize To add to what Whirlwind said - by default, everything collides with everything else and nothing contact anything. This requires every physicsBody to belong to every category (hence categoryBitMask is UInt32Max), every physicsBody's collisionBitMask to include every category (UInt32Max again) and every contactTestBitMask to not incluide any category (hence 0).Telford

© 2022 - 2024 — McMap. All rights reserved.