Jump to content

Scene:Load() doesn't Reload entity's children.


reepblue
 Share

Go to solution Solved by Josh,

Recommended Posts

Notice that components attached to entities with a parent don't save properly. I've ran into an issue where my camera (Which is a child of a pivot) rotation doesn't save automatically. I tried to patch this within the component, but then I noticed that the Load function is skipped when the scene is reloaded. Saving works fine.

This example shows how the component load function is skipped on a scene reload call.

#include "UltraEngine.h"
using namespace UltraEngine;

class TestComponent : public Component
{
public:
    TestComponent()
    {
        name = "TestComponent";
    }

    void Start()
    {
        Print("Start");
    }

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

    virtual bool Load(table& properties, shared_ptr<Stream> binstream, shared_ptr<Map> scene, const LoadFlags flags)
    {
        Print("Loading TestComponent");
        return true;
    }

    virtual bool Save(table& properties, shared_ptr<Stream> binstream, shared_ptr<Map> scene, const SaveFlags flags)
    {
        Print("Saving TestComponent");
        return true;
    }
};

int main(int argc, const char* argv[])
{
    RegisterComponent<TestComponent>();

    if (AllocConsole())
    {
        freopen("conin$", "r", stdin);
        freopen("conout$", "w", stdout);
        freopen("conout$", "w", stderr);
    }

    //Get the displays
    auto displays = GetDisplays();

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

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

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

    //Load scene
    auto scene = CreateMap();
    auto camera = CreateCamera(world);

    auto ent1 = CreatePivot(world);
    scene->entities.push_back(ent1);
    auto ent2 = CreatePivot(world);
    ent2->SetParent(ent1);
    ent2->AddComponent<TestComponent>();
    scene->entities.push_back(ent2);

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        if (window->KeyHit(KEY_F5))
        {
            //Save the starting scene to a file
            Print("Saving...");
            scene->Save("game.sav");
        }

        //Reload the starting scene when space key is pressed
        if (window->KeyHit(KEY_F6))
        {
            Print("Loading....");
            scene->Reload("game.sav");
        }

        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

  • 1 month later...
  • Solution

Okay, I believe I have this fixed and it will be uploaded in a build tomorrow.

Note that in your example,. the saved state cannot be reloaded unless it was saved during the same session, because your entities are created in code. Entities do not have a unique identifier unless they are either loaded from a map that specifies their UUID, or upon the first call to GetUuid().

  • Thanks 1

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