diff --git a/code/Resource/Proxy.h b/code/Resource/Proxy.h index c05fb84bd7..fde4ce21c1 100644 --- a/code/Resource/Proxy.h +++ b/code/Resource/Proxy.h @@ -92,6 +92,12 @@ class Proxy m_tag = (intptr_t)getResource(); } + /*! Un-consume change; useful for forcing a consume again. */ + void unconsume() + { + m_tag = 0; + } + operator bool () const { return getResource() != nullptr; diff --git a/code/UiKit/Editor/PreviewControl.cpp b/code/UiKit/Editor/PreviewControl.cpp index abbfbc5f91..b3916ff2b8 100644 --- a/code/UiKit/Editor/PreviewControl.cpp +++ b/code/UiKit/Editor/PreviewControl.cpp @@ -195,6 +195,13 @@ void PreviewControl::setScaffolding(const Scaffolding* scaffolding) m_scaffoldingClass.clear(); } +void PreviewControl::invalidateScaffolding(const Guid& eventId) +{ + // This will cause the tag in the proxy to be zero so the scaffolding will get re-created. + if (m_scaffolding != nullptr && (Guid)m_scaffolding->getScaffoldingClass() != eventId) + m_scaffoldingClass.unconsume(); +} + void PreviewControl::setDebugWires(bool debugWires) { m_debugWires = debugWires; diff --git a/code/UiKit/Editor/PreviewControl.h b/code/UiKit/Editor/PreviewControl.h index ca7e3ed9be..b4256f4fb7 100644 --- a/code/UiKit/Editor/PreviewControl.h +++ b/code/UiKit/Editor/PreviewControl.h @@ -77,6 +77,8 @@ class PreviewControl : public ui::Widget void setScaffolding(const Scaffolding* scaffolding); + void invalidateScaffolding(const Guid& eventId); + void setDebugWires(bool debugWires); bool getDebugWires() const { return m_debugWires; } diff --git a/code/UiKit/Editor/PreviewEditor.cpp b/code/UiKit/Editor/PreviewEditor.cpp index 7b5f828e1f..18395b57a3 100644 --- a/code/UiKit/Editor/PreviewEditor.cpp +++ b/code/UiKit/Editor/PreviewEditor.cpp @@ -134,7 +134,14 @@ bool PreviewEditor::handleCommand(const ui::Command& command) void PreviewEditor::handleDatabaseEvent(db::Database* database, const Guid& eventId) { if (m_resourceManager && database == m_editor->getOutputDatabase()) - m_resourceManager->reload(eventId, false); + { + if (m_resourceManager->reload(eventId, false)) + { + // Content in resource manager was reloaded; in case it's not the main scaffolding script + // we need to invalidate it manually so the scaffolding is re-created properly. + m_previewControl->invalidateScaffolding(eventId); + } + } } void PreviewEditor::eventPreviewSize(ui::SizeEvent* event)