5.4 - Adding fields to component

I want to create proximity trigger class/component that can be take range values from the editor
i managed to create empty component using Schematyc but it's empty
If i made my fields public it won't show either in the editor
so how to show my class fields in that component

Code: Select all

static void ReflectType(Schematyc::CTypeDesc<CInteractionsComponent>& desc) { desc.SetGUID("{274484BE-C60E-4DE9-A1A8-352A01F33849}"_cry_guid); desc.SetEditorCategory("Game"); desc.SetLabel("MyTrigger"); desc.SetDescription("This will be a Trigger "); desc.SetComponentFlags({ IEntityComponent::EFlags::SchematycEditable, IEntityComponent::EFlags::Socket, IEntityComponent::EFlags::Attach }); }
the only thing that can show here is transform when i add IEntityComponent::EFlags::Transform

I also tried to write functions that set transform but it didn't add transform menu to that component

Code: Select all

static void RegisterTriggerComponent(Schematyc::IEnvRegistrar& registrar) { Schematyc::CEnvRegistrationScope scope = registrar.Scope(IEntity::GetEntityScopeGUID()); { Schematyc::CEnvRegistrationScope componentScope = scope.Register(SCHEMATYC_MAKE_ENV_COMPONENT(CInteractionsComponent)); // Functions { auto pFunction = SCHEMATYC_MAKE_ENV_FUNCTION(&CInteractionsComponent::SetTransform, "DF5B2F50-2A89-4D94-BBD5-A58C6D7C3DEC"_cry_guid, "xxxSetTransform"); pFunction->SetDescription("Set Entity Transformationxxx"); pFunction->BindInput(1, 'tr', "xxxxvtransform"); componentScope.Register(pFunction); } void CInteractionsComponent::SetTransform(const CryTransform::CTransform& transform) { m_pEntity->SetWorldTM(transform.ToMatrix34()); }

Re: 5.4 - Adding fields to component

Ok if I understand properly you want to add properties that will be editable in editor right? So hear me out, because I sorted it out yesterday.

1.Once you have your component c++ file ready you want to create properties struct on the top of your class(or in other file that will be injected later)

Code: Select all

#pragma once #include <CryEntitySystem/IEntityComponent.h> #include <CryEntitySystem/IEntity.h> #include <CrySchematyc/ResourceTypes.h> #include <CrySchematyc/Reflection/TypeDesc.h> struct SYourProperties { //you may need to use these operators later to update changes, so keep it here inline bool operator==(const SYourProperties& rhs) const { return 0 == memcmp(this, &rhs, sizeof(rhs)); } inline bool operator!=(const SYourProperties& rhs) const { return 0 != memcmp(this, &rhs, sizeof(rhs)); } //Variables that you want to have in editor //example float someFloat; Schematyc::GeomFileName sGeomPath; //Check more schematyc types if you need some they are in ResourceTypes.h } //Here you need to reflect your properties static void ReflectType(Schematyc::CTypeDesc<SYourProperties>& desc) { //Obviously use your own guid desc.SetGUID("{9664D389-A32E-4FB1-9068-00CFD4A2ECB0}"_cry_guid); desc.SetLabel("YourProperties"); desc.SetDescription("bla bla bla"); //Here you expose them to your component //If you see something like SomeFloat it means DONT PUT SPACE THERE desc.AddMember(&SYourProperties::someFloat, 'flt', "SomeFloat", "Some float", "blablablala", 0.f) desc.AddMember(&SYourProperties::sGeomPath, 'geom', "GeometryPath", "Geometry path", "blablabla", ""); } //YOUR COMPONENT STARTS BELOW struct YourComponent : public IEntityComponent { public: //blablabla do whatever //Now the Reflect function is important - it will use object to your property struct, which you will create in the end static void ReflectType(Schematyc::CTypeDesc<SWeaponComponent>& desc) { //Your GUID desc.SetGUID("{FDDA1A5D-7360-4B2F-AC2F-44D71AA48303}"_cry_guid); desc.SetEditorCategory("YourCategory"); desc.SetLabel("YourComponent"); desc.SetDescription("blablabla"); desc.SetComponentFlags({ IEntityComponent::EFlags::Transform, IEntityComponent::EFlags::Socket, IEntityComponent::EFlags::Attach }); //EDITOR MEMBERS //THIS WILL BE VISIBLE IN EDITOR!! desc.AddMember(&YourComponent::sYourProperties, 'prop', "YourProperties", "YourProperties", "blablabla", SYourProperties()); //And so on.. if you have other property structures, then add them here in the same way } //Do your shit here //In the end of your class add object (or more if you have more property structures) SYourProperties sYourProperties; //If you have something that you want to update when changing in the editor (for example character that you changed and you want to reload it to your entity) - you can catch this event //If you want to catch it, you will need to compare new settings with the old ones righ? //You will use this in ProcessEvent SYourProperties sPreviousProperties; };
This is it. This will make your properties visible and editable in editor.
Also I will show you how to catch change event:

Code: Select all

//In your component class you need to create event mask method //the last event is the one we will take care of virtual uint64 GetEventMask() const override { return BIT64(ENTITY_EVENT_START_GAME) | BIT64(ENTITY_EVENT_UPDATE) | BIT64(ENTITY_EVENT_COMPONENT_PROPERTY_CHANGED); } //after that you will need to add processEvent method and use it like this: virtual void ProcessEvent(SEntityEvent & event) { if (event.event == ENTITY_EVENT_COMPONENT_PROPERTY_CHANGED) { if (sYourProperties != sPreviousProperties) { sPreviousProperties = sYourProperties ; //Here is your thing. you can create reload function that will assign those properties once again. //For example if you changed model in editor, it will be caught here so you can call now: GetEntity()->LoadGeometry(slot, path); } } }
I know its a lot. But I hope you will get this :)
Cryengine tutorial videos on my Youtube channel! Check it out !

Re: 5.4 - Adding fields to component

Hey Jiangwang,

Try to stay true to the topic, the issue in this topic has been solved and so if you require help on a different subject and cannot find a solution on the forums already you are welcome to start a new topic about your issue.

CRYENGINE Community Coordinator
Here to help the community and social channels grow and thrive.

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

Who is online

Users browsing this forum: No registered users and 2 guests