Why physics not working, PhysicsComponent ?

Hi i so many time can`t find solution for how to run physics in AZ::Entity and PhysicsComponent.


AZ::Uuid _meshComponentID = "{C4C69E93-4C1F-446D-AFAB-F8835AD8EFB0}"; // EditorMeshComponent
AZ::Uuid _meshColliderComponentID = "{2D559EB0-F6FE-46E0-9FCE-E8F375177724}"; // MeshColliderComponent
AZ::Uuid _physicsComponentID = "{A74FA374-8F68-495B-96C1-0BCC8D00EB61}"; // PhysicsComponent
AZ::Entity* _pChildEntity = nullptr;
EBUS_EVENT_RESULT(_pChildEntity, AzFramework::EntityContextRequestBus, CreateEntity, _assetName);
// MeshComponent ------------------------------------------------------------
// Add MeshComponent to entity
_pChildEntity->Deactivate();
AZ::Component* _meshComponent = _pChildEntity->CreateComponent(_meshComponentID);
_pChildEntity->Activate();
// Get Asset path
const string _assetFilePath = "objects/default/primitive_cube.cgf";
// Load asset and register him if not rgisteres
AZ::Data::AssetId _meshAssetId;
EBUS_EVENT_RESULT(_meshAssetId, AZ::Data::AssetCatalogRequestBus, GetAssetIdByPath, _assetFilePath, true);
if (_meshAssetId.IsValid())
{
// assign a the mesh asset (.cgf) EBUS_EVENT_ID(_pChildEntity->GetId(), LmbrCentral::MeshComponentRequestBus, SetMeshAsset, _meshAssetId);
}
// ~MeshComponent -----------------------------------------------------------
// Add PhysicsComponent to entity -------------------------------------
_pChildEntity->Deactivate();
AZ::Component* _physicsComponent = _pChildEntity->CreateComponent(_physicsComponentID);
_pChildEntity->Activate();
EBUS_EVENT_ID(_physicsComponent->GetEntityId(), LmbrCentral::PhysicsComponentRequestBus, SetPhisicsBehavior);
/*
SetPhisicsBehavior
PhysicsComponent.cpp
void PhysicsComponent::SetPhisicsBehavior()
{
m_configuration.m_behavior = AZStd::shared_ptr<CryPhysicsBehavior>(aznew StaticPhysicsBehavior());
}
*/
EBUS_EVENT_ID(_physicsComponent->GetEntityId(), LmbrCentral::PhysicsComponentRequestBus, EnablePhysics);
// ~Add PhysicsComponent to entity ------------------------------------------
// MeshColliderComponent -----------------------------------------------------------------
_pChildEntity->Deactivate();
AZ::Component* _meshColliderComponent = _pChildEntity->CreateComponent(_meshColliderComponentID);
_pChildEntity->Activate();
EBUS_EVENT_ID(_meshColliderComponent->GetId(), LmbrCentral::ColliderComponentEventBus, OnColliderChanged);
// ~MeshColliderComponent ---------------------------------------------------

In editor looking good, but physics not work. Only if i delete MeshColliderComponent and PhysicsComponent and add it hand this working but in c++ cod not work.

On picture bottom all created in c++, but why physics not work can`t understand :(. Pleas Any Help will be nice :slight_smile:

Hello @Anatoliy,

Sorry for the late reply, I will look into this and will hopefully have an answer for you soon.

Thanks!

Hello @Anatoliy,

Just checking back with you, did you get a chance to figure out the physics issue you were experiencing? If not, please let me know and I will make sure to get it addressed as soon as possible :slight_smile:

Thanks!

Hi darkblitz. No, i can’t resolve this, but i found different way to do that. I create needed me entity with components in editor and save him to .slice and then i load from c++ code my slice and all work fine. If i resolve this only in c++ i will write answer here.