Problem with adding pointer of other component as a member field (5.4)

I just started experimenting with Cryengine, so I'm still quite unfamiliar with the engine.
I am trying to add a pointer of CSpawnPointComponent (comes with TPS template) to my component CSpawnPointGroupComponent, and expose it to Schematyc.

This is the way I'm doing it:

Code: Select all

class CSpawnPointGroupComponent final : public IEntityComponent
   CSpawnPointGroupComponent() {};
   virtual ~CSpawnPointGroupComponent() {}

   static void ReflectType(Schematyc::CTypeDesc<CSpawnPointGroupComponent>& desc)
      desc.SetDescription("This spawn point group can be used to store reference of spawn points");
      desc.SetComponentFlags({ IEntityComponent::EFlags::Transform, IEntityComponent::EFlags::Socket, IEntityComponent::EFlags::Attach });
      desc.AddMember(&CSpawnPointGroupComponent::daSpawnPoint, 0, "SpawnPoint", "Spawn Point", "spawn point", nullptr);
   CSpawnPointComponent* daSpawnPoint;

   CSpawnPointComponent* GetSpawnPoint(int idx);

*note that logically daSpawnPoint should be a CSpawnPointComponent* list, just trying out stuff here.

However it couldn't compile, outputting following error message:

Code: Select all

error C2338: Type must be reflected, see TypeDesc.h for details!
note: see reference to function template instantiation 'Schematyc::CClassMemberDesc &Schematyc::CClassDescInterface<TYPE,Schematyc::CClassDesc>::AddMember<IEntityComponent*,nullptr,SSpawnPointGroupProperties>(MEMBER_TYPE SSpawnPointGroupProperties::* ,uint32,const char *,const char *,const char *,const MEMBER_DEFAULT_VALUE_TYPE &)' being compiled
3>          with
3>          [
3>              TYPE=SSpawnPointGroupProperties,
3>              MEMBER_TYPE=IEntityComponent *,
3>              MEMBER_DEFAULT_VALUE_TYPE=nullptr
3>          ]

Wondering what is the proper way to do this.
Last edited by akitsukirin on Thu Sep 28, 2017 1:20 am, edited 1 time in total.

Re: Problem with adding pointer of other component as a member field (5.4)

mknmknmknjk wrote:desc.AddMember(&CSpawnPointGroupComponent::daSpawnPoint, 0, "SpawnPoint", "Spawn Point", "spawn point", SSpawnPointGroupProperties());

default value is not right. there is no way for cryengine to pick entity component to assigh other's component's property like unity for now.
it is not mature.

Thanks for replying and good catch! I was testing around a few different ways, and didn't clean up carefully enough.

So you are saying what I'm trying is not supported by the engine yet, then in the current state, what is the best way to build up the connection between entities?
Like in this case, I want to have a couple of SpawnPointGroup, and each of them are assigned with multiple SpawnPoint, and this step should be done on the editor by designers.
And when a player is getting spawned, depending on their faction or whatever properties, the system chooses the corresponding SpawnPointGroup and then spawn the player at one of its SpawnPoint.
Or something as simple as binding a button to a door.

Re: Problem with adding pointer of other component as a member field (5.4)

I'd advise you to do it a different way to that. Instead of slapping a bunch of spawn components into a single entity, just make a new SpawnGroup component, create an empty entity, add the SpawnGroup component to that entity.

Now the fun part...

Place Spawn entities around the map wherever you want them. Use the in-built "link" tool to link the SpawnGroup to the Spawn entities.

Your SpawnGroup entity will need a piece of code that iterates all the linked entities and does something with them. Maybe that's randomly select one to spawn at, maybe it's the closest - whatever - the basic code to iterate them is like this:

Code: Select all

   // Notify every linked entity.
   auto* entityLinks = GetEntity()->GetEntityLinks();
   while (entityLinks)
      auto pTargetEntity = gEnv->pEntitySystem->GetEntity(entityLinks->entityId);

      // Do something with pTargetEntity here.

      // Next please.
      entityLinks = entityLinks->next;

It's a better design and less code to write too.

Who is online

Users browsing this forum: No registered users and 1 guest