Dreikblack Posted April 3 Posted April 3 Component::Load is not being called for prefabs Test prefab: BoxPrefab.zip #include "Leadwerks.h" #include "ComponentSystem.h" using namespace Leadwerks; int main(int argc, const char* argv[]) { RegisterComponents(); //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); //Create a camera auto camera = CreateCamera(world); camera->SetClearColor(0.125); camera->SetPosition(0, 1, -4); //Create light auto light = CreateBoxLight(world); light->SetRange(-10, 10); light->SetArea(15, 15); light->SetRotation(45, 35, 0); light->SetColor(2); //Create the ground auto ground = CreateBox(world, 10, 1, 10); ground->SetPosition(0, -0.5, 0); ground->SetColor(0, 1, 0); //Create a scene auto scene = CreateScene(); scene->entities.push_back(ground); scene->entities.push_back(light); ground = NULL; light = NULL; vector<shared_ptr<Mover>> movers; //Add some boxes for (int n = 0; n < 10; ++n) { auto box = LoadPrefab(world, "BoxPrefab.pfb"); box->SetColor(0, 0, 1); box->SetPosition(Random(-5, 5), Random(5, 10), Random(-5, 5)); auto comp = box->GetComponent<Mover>(); comp->rotationspeed.y = 50.0f; movers.push_back(comp); scene->entities.push_back(box); } //Save the starting scene to a file scene->Save("game.ultra"); //Main loop while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { if (window->KeyHit(KEY_R)) { for (auto& comp : movers) { comp->rotationspeed.y = 100.0f; } Print("Changed rotation speed"); } //Reload the starting scene when space key is pressed if (window->KeyHit(KEY_SPACE)) { bool b = scene->Reload("game.ultra"); Print(b ? "Reloaded" : "Failed"); } world->Update(); world->Render(framebuffer); } return 0; } Quote
Solution Josh Posted Friday at 05:23 PM Solution Posted Friday at 05:23 PM I have added some code I think will solve this. The binary stream sent to the component will always be NULL when it is being reloaded from a prefab. This feature has turned out to be much more complicated than I originally thought it would be and I regret implementing it. This system is extremely prone to breakage any time I modify anything related to scene loading. I can see now why most games use save points. Every component I distribute should include a Save method, for both Lua and C++. This is easy in simple cases, but with more advanced usage you run into a lot of weird problems, like when a joint is created with objects at one orientation, but now they are both in different positions relative to each other. Or one entity references another entity that was spawned from a component of another entity. It's introduced a permanent ongoing cost to everything I do. The feature will remain in the engine, but I am removing all the scene saving stuff from the documentation and it will not be regarded as an official feature going forward. I do not recommend anyone start a new project using scene saving as a quick save system. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Dreikblack Posted Saturday at 02:06 AM Author Posted Saturday at 02:06 AM 8 hours ago, Josh said: The binary stream sent to the component will always be NULL when it is being reloaded from a prefab. I still have no idea what this stream for 8 hours ago, Josh said: . I can see now why most games use save points. What do you mean by save points? Quote
Josh Posted Saturday at 02:09 AM Posted Saturday at 02:09 AM Just now, Dreikblack said: I still have no idea what this stream for It's for binary data that cannot be stored in JSON format. Just now, Dreikblack said: What do you mean by save points? Where you can only save at certain locations in the game, or it automatically saves when you pass a preset point. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Dreikblack Posted Saturday at 02:15 AM Author Posted Saturday at 02:15 AM 6 minutes ago, Josh said: Where you can only save at certain locations in the game, or it automatically saves when you pass a preset point. I don't see how it would change anything. Quote
Josh Posted Saturday at 02:34 AM Posted Saturday at 02:34 AM Because you can count on some things being resolved, like maybe no active enemies around you, the player is not going through a door. In the case of Amnesia, you have to touch an object to save, which means you can't be holding anything in your hands at that moment. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
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.