reepblue Posted November 13, 2023 Share Posted November 13, 2023 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; } Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted December 15, 2023 Share Posted December 15, 2023 I can confirm the Reload() method is not written in a way that supports this correctly and I need to change it a bit... Quote 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 More sharing options...
Solution Josh Posted December 15, 2023 Solution Share Posted December 15, 2023 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(). 1 Quote 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 More sharing options...
Recommended Posts
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.