How to make C++ component appear in the editor?

I’m following this user guide: Creating a Component

to create a C++ component for Lumberyard, but I don’t know where did I go wrong that the component won’t appear in the editor.

I did the following step:

  1. Add new file into the project I created:

PlayerCtrlComponent.cpp & PlayerCtrlComponent.h

  1. I copy the code of a component (CameraRigComponent) for thePlayerCtrlComponent, I do this for testing purpose, I just want to see if the component actually can be assigned to an entity.

  2. I edit the following things of copied CameraRigComponent, just to make the editor think the component is not duplicated:

*namespace Camera —> TestTest

*GUID, I replace the own one with the new one

*class name CameraRigComponent --> PlayerCtrlComponent

*Edit the following code

    void PlayerCtrlComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC("PlayerCtrlService"));
}
void PlayerCtrlComponent::Reflect(AZ::ReflectContext* reflection)
{
...
editContext->Class<PlayerCtrlComponent>("Player Ctrl", "The Player Ctrl component can be used to add and remove behaviors to drive your player entity")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Category, "TestTest")
...
}
  1. Close the Lumberyard Editor & rebuild the project that I created (I re-build only that project, using Visual Studio feature: project only > build only Empty_Project)

  2. After the build is success, I re-open the Lumberyard Editor, but the component doesn’t show up when I click the button Add component for an Entity.

Am I missing something?

First, thank you for your answer.

So when I when replace the “Empty_ProjectSystemComponent” with “PlayerCtrlComponent” in the file “Empty_ProjectModule.cpp” (this file register the component), I got a bunch of linkage error. So I think I’ll focus on making the “Empty_ProjectSystemComponent” appear in the edit now (This is the default component which is generated automatically by Lumberyard). But I don’t know why this “Empty_ProjectSystemComponent” won’t appear in the editor. How to make “Empty_ProjectSystemComponent” appear in the editor?

Did you register your PlayerCtrlComponent?

https://docs.aws.amazon.com/lumberyard/latest/userguide/component-entity-system-pg-registering-your-component.html

thanks for your help.

About the linkage error I mentioned earlier in the first comment, I figure it out, it just because I forgot to add PlayerCtrlComponent.cpp & PlayerCtrlComponent.h into the file “empty_project.waf_files”. After I edit the file empty_project.waf_files, I can register the PlayerCtrlComponent with the file Empty_ProjectModule.cpp.

About the “AppearsInAddComponentMenu”, the PlayerCtrlComponent has this attribute because it’s a copied of CameraRigComponent.

So I think the culprit must be something else, because the PlayerCtrlComponent still doesn’t show up.

I think I better re-read the user manual (

Programmer’s Guide to Entities and Components &

Using Gems to Add Modular Features and Assets

) again to make sure I didn’t miss anything. I’ll be back when I’ve done reading.

Finally I figured it out. No wonder why I did this all morning and still can’t find anything in the editor. I must re-build my game project (Lumberyard’s way).

So here I sum up the hold thing:

(The
purpose of the following step is to make a component appear in the editor, I gonna borrow the code of the component CameraRig cause it’s the simplest component)

Assume your project name is Empty_Project

Step 0: Read the manual so you have basic understanding for the component C++ structure

Programmer’s Guide to Entities and Components & Using Gems to Add Modular Features and Assets

Step 1: Close Lumberyard Editor if it’s opened & open the game project with Visual Studio

Step 2: Ok, here I borrow the code of CameraRig component for education purpose only.

Add the classes of the file:

CameraRigComponent.cpp

CameraRigComponent.h

CameraFramework’s header files

Don’t forget to edit the namespace, GUID.

You can edit the Category for the component

For example, I changed it to HDNShare

->Attribute(AZ::Edit::Attributes::Category, "HDNShare")//"Camera")

(At this moment it’s just these files, it could be changed in the future though)

Step 3: Register the component (Thanks to brunohgouveia for reminding me this). You can check the file CameraFrameworkGem.cpp

.Actually I copy the whole CameraFrameworkModule class, just remove this code of that class

                    // This is an internal Amazon gem, so register it's components for metrics tracking, otherwise the name of the component won't get sent back. // IF YOU ARE A THIRDPARTY WRITING A GEM, DO NOT REGISTER YOUR COMPONENTS WITH EditorMetricsComponentRegistrationBus
AZStd::vector<AZ::Uuid> typeIds;
typeIds.reserve(m_descriptors.size()); for (AZ::ComponentDescriptor* descriptor : m_descriptors)
{
typeIds.emplace_back(descriptor->GetUuid());
}
EBUS_EVENT(AzFramework::MetricsPlainTextNameRegistrationBus, RegisterForNameSending, typeIds);

As a matter of fact, it did tell you (a third-party writing gem) don’t copy this code.

Also pay attention to the namespace and GUID (just like in step 2)

Step 4: don’t forget to edit the waf file (empty_project.waf_files), you can check this file as an example.

Step 5:
Build Only Empty_Project (In Visual Studio, Right click Empty_Project > Project Only > Build Only Empty_Project), make sure the build is
successful.

Step 6: Rebuild game project as Lumberyard tell you: Rebuilding Your Game Project

Step 7: After rebuilding successfully, open Lumberyard Editor and now you can find your component.

First, Empty_ProjectSystemComponent is a System component (which I believe it’s not going to show up in the Entity View, but in the “System
Entity Editor”, so first check if it shows up there).

Docs: https://docs.aws.amazon.com/lumberyard/latest/userguide/component-entity-system-pg-creating-system-components.html

Second,
I believe that if you don’t have a separate EditorComponent implementation for you component, you need to add the “AppearsInAddComponentMenu” attribute to the component ClassElement when
defining it to the EditContext (also take a look in the link above).

Be
aware that I just started with Lumberyard (2~3 days ago) and thats what
I think it’s going on. The engine code is well architected and organized, but it’s quite huge and I don’t really have a solid knowledge
of these systems yet. Therefore, I’m not 100% confident that I’m right.