5.4 C++ Component getting collision pointer

#1
Welcome. I tried to get objects colliding with each other in new component system, but no way.
I obviously used

Code: Select all

virtual uint64 GetEventMask() const override { return BIT64(ENTITY_EVENT_START_GAME) | BIT64(ENTITY_EVENT_UPDATE) | BIT64(ENTITY_EVENT_COLLISION); }
and I am trying to catch collision event like this:

Code: Select all

virtual void ProcessEvent(SEntityEvent &event) override { if (event.event) { //Collision is being catched properly } }
So I managed to get this work. The only bad thing is I can't get collider !
In previous system in IGameObjectExtension there was HandleEvent method that had SGameObjectEvent parameter, and this parameter had pointer to the collider.

Code: Select all

event.ptr
Current ProcessEvent has only SEntityEvent parameter, which does not have any sort of pointer. How Do I get collider then? I tries nParam to see if any of 4 slots of this array returns maybe entityId, but nope.
Cryengine tutorial videos on my Youtube channel! Check it out !
https://www.youtube.com/user/MusicForLifePL20

Re: 5.4 C++ Component getting collision pointer

#2
Figured out! If anyone is looking for solution there it is.. Getting collision in ProcessEvent method:

Code: Select all

void ProcessEvent(SEntityEvent& event) override { switch (event.event) { case ENTITY_EVENT_COLLISION: { EventPhysCollision *physCollision = reinterpret_cast<EventPhysCollision *>(event.nParam[0]); if (physCollision) { IPhysicalEntity *pThisEntityPhysics = physCollision->pEntity[0]; IEntity *pThisEntity= gEnv->pEntitySystem->GetEntityFromPhysics(pColliderPhys); IPhysicalEntity *pColliderPhysics= physCollision->pEntity[1]; IEntity *pCollider = gEnv->pEntitySystem->GetEntityFromPhysics(pThisPhys); //Now just check if the collider entity is valid if(pCollider) { //Do something to your collider } } } break; } }
Cryengine tutorial videos on my Youtube channel! Check it out !
https://www.youtube.com/user/MusicForLifePL20

Re: 5.4 C++ Component getting collision pointer

#3
Figured out! If anyone is looking for solution there it is.. Getting collision in ProcessEvent method:

Code: Select all

void ProcessEvent(SEntityEvent& event) override { switch (event.event) { case ENTITY_EVENT_COLLISION: { EventPhysCollision *physCollision = reinterpret_cast<EventPhysCollision *>(event.nParam[0]); if (physCollision) { IPhysicalEntity *pThisEntityPhysics = physCollision->pEntity[0]; IEntity *pThisEntity= gEnv->pEntitySystem->GetEntityFromPhysics(pColliderPhys); IPhysicalEntity *pColliderPhysics= physCollision->pEntity[1]; IEntity *pCollider = gEnv->pEntitySystem->GetEntityFromPhysics(pThisPhys); //Now just check if the collider entity is valid if(pCollider) { //Do something to your collider } } } break; } }
You tested this method? I tested , it is wrong! May be I am wrong cause I get a nulptr value of pCollider, but it is here a new method? Or that is true?
C++ Programmer
https://www.youtube.com/AhmadKarami

Re: 5.4 C++ Component getting collision pointer

#4
You tested this method? I tested , it is wrong! May be I am wrong cause I get a nulptr value of pCollider, but it is here a new method? Or that is true?
It could be that the IPhysicalEntity was not part of an Entity, so GetEntityFromPhysics would return a nullptr. It looks like there's also a tiny mistake in the code snippet, because it is using pColliderPhys for pThisEntity and pThisPhys for pCollider. This is how I think it was intended to be used:

Code: Select all

void ProcessEvent(SEntityEvent& event) override
{
switch (event.event)
{
case ENTITY_EVENT_COLLISION:
{
EventPhysCollision *physCollision = reinterpret_cast<EventPhysCollision *>(event.nParam[0]);
if (physCollision)
{
IPhysicalEntity *pThisEntityPhysics = physCollision->pEntity[0];
IEntity *pThisEntity = gEnv->pEntitySystem->GetEntityFromPhysics(pThisEntityPhysics);
IPhysicalEntity *pColliderPhysics= physCollision->pEntity[1];
IEntity *pCollider = gEnv->pEntitySystem->GetEntityFromPhysics(pColliderPhysics);
//Now just check if the collider entity is valid
if(pCollider)
{
//Do something to your collider
}
}
}
break;
}
}
Also keep in mind that this event has two parameters:

Code: Select all

//! nParam[0] = const EventPhysCollision *), contains collision info and can be obtained as: reinterpret_cast<const EventPhysCollision*>(event.nParam[0])
//! nParam[1] 0 if we are the source of the collision), otherwise 1.
You can also have a look at this code to see how we use this event to gather all the collision information to send it to C#.

Re: 5.4 C++ Component getting collision pointer

#5
You tested this method? I tested , it is wrong! May be I am wrong cause I get a nulptr value of pCollider, but it is here a new method? Or that is true?
It could be that the IPhysicalEntity was not part of an Entity, so GetEntityFromPhysics would return a nullptr. It looks like there's also a tiny mistake in the code snippet, because it is using pColliderPhys for pThisEntity and pThisPhys for pCollider. This is how I think it was intended to be used:

Code: Select all

void ProcessEvent(SEntityEvent& event) override
{
switch (event.event)
{
case ENTITY_EVENT_COLLISION:
{
EventPhysCollision *physCollision = reinterpret_cast<EventPhysCollision *>(event.nParam[0]);
if (physCollision)
{
IPhysicalEntity *pThisEntityPhysics = physCollision->pEntity[0];
IEntity *pThisEntity = gEnv->pEntitySystem->GetEntityFromPhysics(pThisEntityPhysics);
IPhysicalEntity *pColliderPhysics= physCollision->pEntity[1];
IEntity *pCollider = gEnv->pEntitySystem->GetEntityFromPhysics(pColliderPhysics);
//Now just check if the collider entity is valid
if(pCollider)
{
//Do something to your collider
}
}
}
break;
}
}
Also keep in mind that this event has two parameters:

Code: Select all

//! nParam[0] = const EventPhysCollision *), contains collision info and can be obtained as: reinterpret_cast<const EventPhysCollision*>(event.nParam[0])
//! nParam[1] 0 if we are the source of the collision), otherwise 1.
You can also have a look at this code to see how we use this event to gather all the collision information to send it to C#.
Solved , thanks a lot my friend :-)
C++ Programmer
https://www.youtube.com/AhmadKarami

Who is online

Users browsing this forum: No registered users and 1 guest