Jump to content

[C++] Editor doesn't show components


LxrdKxnny
 Share

Go to solution Solved by Dreikblack,

Recommended Posts

Hello there,

I have followed the official documentation for creating components and getting them to display in the editor but I still can't see the component in the editor. I've created the component under 'Components/Character/CharacterMovement.hpp' and I have also added a 'CharacterMovement.json' file alongside it.

I have also registered the component in 'ComponentSystem.h' but the component still won't show in the editor:

#pragma once

#include "UltraEngine.h"
#include "Components/Character/CharacterMovement.hpp"

using namespace UltraEngine;

inline void RegisterComponents()
{
    RegisterComponent<CharacterMovement>();
}

Here is 'CharacterMovement.hpp' file:

#pragma once

#include "UltraEngine.h"

using namespace UltraEngine;

class CharacterMovement : public Component
{
public:
    CharacterMovement()
    {
        name = "CharacterMovement";
    }
    
    void Update() override
    {
        // ...
    }

    bool Load(table& properties, shared_ptr<Stream> binstream, shared_ptr<Map> scene, const LoadFlags flags) override
    {
        if (properties["m_WalkSpeed"].is_number())
        {
            m_WalkSpeed = properties["m_WalkSpeed"];
        }
    
        if (properties["m_SprintSpeed"].is_number())
        {
            m_SprintSpeed = properties["m_SprintSpeed"];
        }

        return true;
    }

    bool Save(table& properties, shared_ptr<Stream> binstream, shared_ptr<Map> scene, const SaveFlags flags) override
    {
        properties["m_WalkSpeed"] = m_WalkSpeed;
        properties["m_SprintSpeed"] = m_SprintSpeed;

        return true;
    }

    std::shared_ptr<Component> Copy() override
    {
        return std::make_shared<CharacterMovement>(*this);
    }

public:
    int m_WalkSpeed = 5.0f;
    int m_SprintSpeed = 10.0f;
};

Here is the 'CharacterMovement.json' file:

{
  "component": {
    "properties": [
      {
        "name": "m_WalkSpeed",
        "label": "Walk Speed",
        "value": "5"
      },
      {
        "name": "m_SprintSpeed",
        "label": "Sprint Speed",
        "value": "10"
      }
    ]
  }
}

I'm not sure what's happening here but if someone knows, I'd really appreciate the help! :)

image.png

image.png

Link to comment
Share on other sites

Your numeric values should be numbers instead of strings.  Not sure if this is why it's not showing up though... maybe try creating one ".h" file and another ".cpp" file for the definitions.  I think this changed a while back so it might need both files as well as the json file now.  Take a look at the default components to see how they work.

{
  "component": {
    "properties": [
      {
        "name": "m_WalkSpeed",
        "label": "Walk Speed",
        "value": 5.0
      },
      {
        "name": "m_SprintSpeed",
        "label": "Sprint Speed",
        "value": 10.0
      }
    ]
  }
}

 

Link to comment
Share on other sites

56 minutes ago, SpiderPig said:

Your numeric values should be numbers instead of strings.  Not sure if this is why it's not showing up though... maybe try creating one ".h" file and another ".cpp" file for the definitions.  I think this changed a while back so it might need both files as well as the json file now.  Take a look at the default components to see how they work.

{
  "component": {
    "properties": [
      {
        "name": "m_WalkSpeed",
        "label": "Walk Speed",
        "value": 5.0
      },
      {
        "name": "m_SprintSpeed",
        "label": "Sprint Speed",
        "value": 10.0
      }
    ]
  }
}

I added the changes but it still doesn't seem to have fixed the issue. I'm unsure why this isn't working to be honest. I don't think there's anything else I've missed unless the folder structure I am using is incorrect:
image.png.c55d2f3b8292dfba02c75aa624509cad.png

Link to comment
Share on other sites

17 minutes ago, Dreikblack said:

Works for me with original .json from top post. Try to create new component via editor with + button

image.png.249111de9f39822c90b7d51a55c274c0.png
btw maybe some letter is not latin? Like Cyrillic 'C' instead of English one in folder and file name.

I'm not sure why but adding the file manually didn't work, but creating the component from the editor instead did work. Thank you so much! :)

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...