Jump to content

Component of new entity that was created by entity->Instantiate() has a pointer to original entity


Dreikblack
 Share

Go to solution Solved by Josh,

Recommended Posts

Looks like a component of new entity that was created by entity->Instantiate() has a pointer to original entity.

Several months it worked fine. Maybe something went wrong when public entity pointer was replaced by GetEntity() method.

Steam beta branch.

image.thumb.png.a1a7d2ab275a1b0e324c93c81b4b43b1.png

#include "UltraEngine.h"
#include "ComponentSystem.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    //Get the displays
    auto displays = GetDisplays();

    //Create a window
    auto window = CreateWindow("Ultra Engine", 0, 0, 1200, 800, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);

    //Create a world
    auto world = CreateWorld();

    //Create a framebuffer
    auto framebuffer = CreateFramebuffer(window);

    //Create a camera
    auto camera = CreateCamera(world);
    camera->SetClearColor(0.125);
    camera->SetFov(70);
    camera->SetPosition(0, 0, -3);

    //Create a light
    auto light = CreateBoxLight(world);
    light->SetRotation(35, 45, 0);
    light->SetRange(-10, 10);

    //Create a box
    auto box = CreateBox(world);
    box->SetPosition(1, 1, 1);

    auto component = box->AddComponent<Mover>();
    component->rotationspeed.y = 45;

    auto newBox = box->Instantiate(world, true, true);
    newBox->SetPosition(2, 2, 2);

    auto componentTest = newBox->GetComponent<Mover>();

    Print("first box pos x:");
    Print(box->GetPosition().x);
    Print(component->GetEntity()->GetPosition().x);
    Print("second box pos x:");
    Print(newBox->GetPosition().x);
    Print(componentTest->GetEntity()->GetPosition().x);

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        world->Update();
        world->Render(framebuffer, false);
    }
    return 0;
}

 

  • Thanks 1
Link to comment
Share on other sites

It's fixed on the standalone now. Verified with this example:

#include "UltraEngine.h"
#include "Components/Motion/Mover.hpp"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    //Create a world
    auto world = CreateWorld();

    //Create a box
    auto box1 = CreateBox(world);
    auto component1 = box1->AddComponent<Mover>();

    auto box2 = box1->Instantiate(world, true, true);
    auto component2 = box2->GetComponent<Mover>();

    Assert(component1->GetEntity() != component2->GetEntity());

    return 0;
}

 

My job is to make tools you love, with the features you want, and performance you can't live without.

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...