Area using Editor and attaching a custom compenent C++

#1
Hello all,

Im new to cryengine i was trying somethings lately and i wonder how to get the "pressure plate" working ?
So i add area using the editor added a custom compenent using c++
but when i run the game using editor some events occur (but no collision)
and when i run it through compilation nothing happen
So im trying to get it working for both and fixing the collision so when the player enter the area it gonna show text in console!

My code for component :
H file

Code: Select all

#pragma once
#include "StdAfx.h"
#include <CryEntitySystem/IEntityComponent.h>
#include <CryEntitySystem/IEntity.h>


class CTriggerVolume final : public IEntityComponent
{
public:
CTriggerVolume() = default;
virtual ~CTriggerVolume() {}

// Reflect type to set a unique identifier for this component
// and provide additional information to expose it in the sandbox
static void ReflectType(Schematyc::CTypeDesc<CTriggerVolume>& desc)
{
desc.SetGUID("{32AF29F2-D63F-48E8-8346-33331B09D095}"_cry_guid);
desc.SetEditorCategory("Game");
desc.SetLabel("TriggerVolume");
desc.SetDescription("This TriggerVolume");
desc.SetComponentFlags({ IEntityComponent::EFlags::Transform, IEntityComponent::EFlags::Socket, IEntityComponent::EFlags::Attach});
}

public:
// IEntityComponent
virtual void Initialize() override;
virtual void ProcessEvent(const SEntityEvent& event) override;
virtual uint64 GetEventMask() const override;

};
CPP file

Code: Select all

#include "StdAfx.h"
#include "VolumeTrigger.h"

#include <CrySchematyc/Reflection/TypeDesc.h>
#include <CrySchematyc/Utils/EnumFlags.h>
#include <CrySchematyc/Env/IEnvRegistry.h>
#include <CrySchematyc/Env/IEnvRegistrar.h>
#include <CrySchematyc/Env/Elements/EnvComponent.h>
#include <CrySchematyc/Env/Elements/EnvFunction.h>
#include <CrySchematyc/Env/Elements/EnvSignal.h>
#include <CrySchematyc/ResourceTypes.h>
#include <CrySchematyc/MathTypes.h>
#include <CrySchematyc/Utils/SharedString.h>

static void RegisterTriggerVolume(Schematyc::IEnvRegistrar& registrar)
{
Schematyc::CEnvRegistrationScope scope = registrar.Scope(IEntity::GetEntityScopeGUID());
{
Schematyc::CEnvRegistrationScope componentScope = scope.Register(SCHEMATYC_MAKE_ENV_COMPONENT(CTriggerVolume));
// Functions
{
}
}
}

CRY_STATIC_AUTO_REGISTER_FUNCTION(&RegisterTriggerVolume)

void CTriggerVolume::Initialize()
{
CryLog("ENTITY FOUND!");
}

void CTriggerVolume::ProcessEvent(const SEntityEvent& event)
{
if (event.event == ENTITY_EVENT_COLLISION) {
CryLog("You entred the box!");
}
else if (event.event == ENTITY_EVENT_START_GAME)
{
CryLog("***GAME STARTED ***");
}
}

uint64 CTriggerVolume::GetEventMask() const
{
return ENTITY_EVENT_BIT(ENTITY_EVENT_START_GAME) | ENTITY_EVENT_BIT(ENTITY_EVENT_COLLISION);
}

Re: Area using Editor and attaching a custom compenent C++

#2
Hi there,

It may be easier to use the events ENTITY_EVENT_ENTERAREA and ENTITY_EVENT_LEAVEAREA.
Then you can link any kind of area (Sphere/Box or Custom Shape) to the entity holding your component and receive any of these events.
Uniflare
CRYENGINE Community Coordinator
Here to help the community and social channels grow and thrive.

My personal belongings;
Beginner Guides | My GitHub | Splash Plugin

Re: Area using Editor and attaching a custom compenent C++

#3
Hey,
so I think we have make distinction between collision events and area events here.
So if you want to receive an ENTITY_EVENT_COLLISION event both entities have to be physicalized and have to have a mesh with a collider, those events will then only be send if a actual collision between the collider happened.
On the other hand if want to receive ENTITY_EVENT_ENTERAREA, ENTITY_EVENT_LEAVEAREA you have to use the area trigger, which don't represent real geometry in the level. The areas are just fictional volumes in the level which the player can't see or interactive with really, they are mostly used for logic within the level to trigger cut scenes, actions or to mark certain level section.

Below I will provide a simple implementation of an area component you could use for your pressure plate. Keep in mind that if you want other entities to trigger area events you have to add a special entity flag called ENTITY_FLAG_TRIGGER_AREAS to those entities.

Code: Select all

#include <CryEntitySystem/IEntitySystem.h> // Example of a component that receives enter and leave events from a virtual box positioned on the entity class CMyTriggerComponent : public IEntityComponent { public: virtual ~CMyTriggerComponent() = default; static void ReflectType(Schematyc::CTypeDesc<CMyTriggerComponent>& desc) { /* Reflect the component GUID in here. */ } virtual void Initialize() override { // Create a new IEntityTriggerComponent instance, responsible for registering our entity in the proximity grid IEntityTriggerComponent* pTriggerComponent = m_pEntity->CreateComponent<IEntityTriggerComponent>(); // Listen to area events in a 2m^3 box around the entity const Vec3 triggerBoxSize = Vec3(2, 2, 2); // Create an axis aligned bounding box, ensuring that we listen to events around the entity translation const AABB triggerBounds = AABB(triggerBoxSize * -0.5f, triggerBoxSize * 0.5f); // Now set the trigger bounds on the trigger component pTriggerComponent->SetTriggerBounds(triggerBounds); } virtual void ProcessEvent(const SEntityEvent& event) override { if (event.event == ENTITY_EVENT_ENTERAREA) { // Get the entity identifier of the entity that just entered our shape const EntityId enteredEntityId = static_cast<EntityId>(event.nParam[0]); } else if (event.event == ENTITY_EVENT_LEAVEAREA) { // Get the entity identifier of the entity that just left our shape const EntityId leftEntityId = static_cast<EntityId>(event.nParam[0]); } } virtual uint64 GetEventMask() const override { // Listen to the enter and leave events, in order to receive callbacks above when entities enter our trigger box return BIT64(ENTITY_EVENT_ENTERAREA) | BIT64(ENTITY_EVENT_LEAVEAREA); } };
I hope I could clarify the topic and help with your problem.

Cheers,
Alex

Who is online

Users browsing this forum: No registered users and 1 guest

cron