Dreikblack Posted January 18, 2025 Posted January 18, 2025 If i just use component with saved scene from Load() everything works. But if i save entity as prefab, scene will expire. Most likely it's due scene in Load is Prefab's scene - scene->navmeshes is empty for prefab component in Load when real scene have it. Component and its prefab example TestPrefab.zip Quote Check out Slipgate Tactics - turn based tactics Quake fan game, which is made with Ultra Engine/Leadwerks 5: https://www.leadwerks.com/community/topic/61480-slipgate-tactics-demo/
Josh Posted January 23, 2025 Posted January 23, 2025 This is by design. The prefab has a temporary scene all entities are loaded into, which allows each component to retrieve the objects in that prefab. What happens if you move the navmesh code into the first call to the Update() method? Something like this: class component { std::weak_ptr<Scene> scene; } void component::Update() { auto scene = this->scene.lock(); if (not scene) { scene = MyGame->scene; this->scene = scene; if (scene and not scene->navmeshes.empty()) { //do some things here... } } } Quote Let's build cool stuff and have fun.
Dreikblack Posted January 24, 2025 Author Posted January 24, 2025 3 hours ago, Josh said: scene = MyGame->scene; This is something that i can do in my game by using Singletones, but it's not proper option for components to share in Downloads or tutorials. 3 hours ago, Josh said: component to retrieve the objects in that prefab. Which should be possible via kids of root entity and normal scene anyway? Quote Check out Slipgate Tactics - turn based tactics Quake fan game, which is made with Ultra Engine/Leadwerks 5: https://www.leadwerks.com/community/topic/61480-slipgate-tactics-demo/
Dreikblack Posted January 24, 2025 Author Posted January 24, 2025 And if it's needed internally can be normal scene be send to component Load() since it's called per instance anyway? Quote Check out Slipgate Tactics - turn based tactics Quake fan game, which is made with Ultra Engine/Leadwerks 5: https://www.leadwerks.com/community/topic/61480-slipgate-tactics-demo/
Josh Posted January 24, 2025 Posted January 24, 2025 2 hours ago, Dreikblack said: This is something that i can do in my game by using Singletones, but it's not proper option for components to share in Downloads or tutorials. Which should be possible via kids of root entity and normal scene anyway? Not exactly. Prefabs have a UUID for each entity, but since there can be multiple prefabs of the same file loaded, a new UUID is generated when the prefab gets added to the main scene. It's messy. 1 Quote Let's build cool stuff and have fun.
Dreikblack Posted January 24, 2025 Author Posted January 24, 2025 Maybe something like std::list<std::weak_ptr<Scene>> scenes; can be added to World? Quote Check out Slipgate Tactics - turn based tactics Quake fan game, which is made with Ultra Engine/Leadwerks 5: https://www.leadwerks.com/community/topic/61480-slipgate-tactics-demo/
Josh Posted January 24, 2025 Posted January 24, 2025 I am going to leave this open because I want to think about it more. Quote Let's build cool stuff and have fun.
Josh Posted March 4, 2025 Posted March 4, 2025 Okay, it appears the way you are using the prefab scene object is to add a created entity into the scene. This seems like a bad approach to me. Is there some reason this must be done? auto targetPivotShared = CreatePivot(gameCamera->GetWorld()); targetPivotShared->SetPickMode(PICK_NONE); targetPivotShared->SetPosition(targetPosition); targetPivotShared->SetRotation(0, gameCamera->GetRotation(true).y, gameCamera->GetRotation(true).z); gameCamera->SetParent(targetPivotShared); sceneWeak.lock()->AddEntity(targetPivotShared); targetPivot = targetPivotShared; Quote Let's build cool stuff and have fun.
Dreikblack Posted March 5, 2025 Author Posted March 5, 2025 7 hours ago, Josh said: This seems like a bad approach to me. Is there some reason this must be done? It's most clear approach if anything for this case and just one of many uses of scene. Another often case is getting navemesh. It's done to temporally save pivot until scene will be deleted. Camera have to be parented to this pivot so camera component can't have strong reference to the pivot to avoid circular references. The only another way to do it would be making extra component for a pivot which is already worse approach. And no, it will not work if i will use pivot instead of camera and spawn camera with component because it would be require a LOT of extra stuff to make it work (pivot should be on the ground, so it could not be placed in the Editor like camera in air etc.). Quote Check out Slipgate Tactics - turn based tactics Quake fan game, which is made with Ultra Engine/Leadwerks 5: https://www.leadwerks.com/community/topic/61480-slipgate-tactics-demo/
Josh Posted March 7, 2025 Posted March 7, 2025 The need to access the navmesh in order to create navigation agents is a good argument for some solution to be found for this. Maybe the engine could replace all entity UUID values with the new ones in the loaded scene and pass the scene handle to the Load command. Quote Let's build cool stuff and have fun.
Solution Josh Posted March 8, 2025 Solution Posted March 8, 2025 I have made the change and I am compiling now. If everything works correctly, you may mark this issue solved. 1 Quote Let's build cool stuff and have fun.
Josh Posted March 8, 2025 Posted March 8, 2025 FYI, this means that prefabs cannot contain navmeshes that can be accessed. I think this is the right choice. Quote Let's build cool stuff and have fun.
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.