Creating Collision Layers and Groups Programmatically

Retrieve layers and groups

You can retrieve instances of collision layers and groups that you created in O3DE Editor as shown below. These methods perform a lookup of the layers defined in the PhysX Configuration tool. If no collision layer is found that matches the name, the default layer \(`0`\) is returned.

CollisionLayer layer("MyLayer");
CollisionGroup group("MyGroup");

You can also use a request bus to look up layers and groups, as in the following code:

CollisionLayer layer;
CollisionRequestBus::BroadcastResult(layer, &Physics::CollisionRequests::GetCollisionLayerByName, layerName);
CollisionGroup group;
CollisionRequestBus::BroadcastResult(group, &Physics::CollisionRequests::GetCollisionGroupByName, groupName);

Create layers and groups

You can create collision layers and groups in code at runtime. This is useful in scenarios where you might not be able to predefine collision layers and groups, such as projects that generate assets procedurally at runtime.

The following example code creates a collision group at runtime that contains an Enemy layer and a Tree layer.

CollisionLayer layer1("Enemy"), layer2("Tree");
CollisionGroup group = AzFramework::Physics::CollisionGroup::None;
group.SetLayer(layer1, true);
group.SetLayer(layer2, true);

If all the layers required to construct the collision group are known, you can use overloaded operators, as in the following example:

CollisionGroup group = CollisionLayer("Layer1") | CollisionLayer("Layer2") | CollisionLayer("Layer3");

Copyright © 2026 DawnEngine. All rights reserved.

DawnEngine is a commercial 3D engine distributed under the DawnEngine end-user license agreement. Engine binaries and source are proprietary and are not covered by the licenses below.

Documentation only: the prose and templates on this site are a derivative work of Open 3D Engine (O3DE) documentation by the O3DE Contributors, used under CC BY 4.0 (documentation content), Apache 2.0 (site code), and the MIT license (inline code samples).

The open-source 3D engine that DawnEngine is built on top of is Open 3D Engine . DawnEngine is not affiliated with, endorsed by, or sponsored by The Linux Foundation or the O3DE project. “O3DE” and “Open 3D Engine” are trademarks of The Linux Foundation.