Expose prefab instantiation to Lua#816
Conversation
adriengivry
left a comment
There was a problem hiding this comment.
Instantiate prefab should be a method in OvCore::SceneSystem::Scene, and Lua should expose it. Implementation should not live in Lua bindings.
While reviewing the runtime path, I found that prefab actors spawned during play mode could receive lifecycle callbacks before deserialization was complete. I fixed this by deferring startup until the instantiated hierarchy has been fully deserialized |
| const auto actors = m_batchCreatedActors; | ||
| m_batchCreatedActors.clear(); |
There was a problem hiding this comment.
Why would we copy m_batchCreatedActors here?
Instead:
const auto& actors = m_batchCreatedActors; // Or you could use m_batchCreatedActors directly in the for loops
// All the for loops go here
m_batchActorCreation = false
m_batchCreatedActors.clear();|
|
||
| OvCore::ECS::Actor* OvCore::SceneSystem::Scene::InstantiatePrefab(const std::string& p_prefabPath) | ||
| { | ||
| return InstantiatePrefab(p_prefabPath, OvTools::Utils::OptRef<ECS::Actor>{}); |
There was a problem hiding this comment.
Use std::nullopt instead of OvTools::Utils::OptRef<ECS::Actor>{}
|
|
||
| OvCore::ECS::Actor* OvCore::SceneSystem::Scene::InstantiatePrefab(const std::string& p_prefabPath, ECS::Actor& p_parent) | ||
| { | ||
| return InstantiatePrefab(p_prefabPath, OvTools::Utils::OptRef<ECS::Actor>{ p_parent }); |
There was a problem hiding this comment.
You can use p_parent implicitly directly instead of OvTools::Utils::OptRef<ECS::Actor>{ p_parent }
| const bool shouldBatchActorCreation = m_isPlaying; | ||
| if (shouldBatchActorCreation) | ||
| { | ||
| BeginBatchActorCreation(); |
There was a problem hiding this comment.
You should always call BeginBatchActorCreation.
How it is implemented internally shouldn't matter to InstantiatePrefab.
EndBatchActorCreation should decide which methods to call based on the state of m_isPlaying when it's called.
Description
Adds
Scene:InstantiatePrefab(...)to Lua with optional local transform and parent.Related Issue(s)
Fixes #808
Review Guidance
Focus on Lua overloads, prefab path resolution, and prefab source normalization.
Screenshots/GIFs
N/A
AI Usage Disclosure
Refactored code / Debugging
Checklist