sityrax Posted November 13 Posted November 13 Здравствуйте! Есть ли где-нибудь событие или функция обратного вызова типа Update или Init, которое позволило бы узнать, что нода или компонент были удалены (например методом DeleteForce, DeleteLater или перезагрузкой мира)?
Amerio.Stephane Posted November 13 Posted November 13 Hi, you can implement the shutdown method of a custom component, and then add this component to the node which destruction you want to monitor. #pragma once #include <UnigineComponentSystem.h> #include <plugins/Unigine/IG/UnigineIG.h> #include <plugins/Unigine/IG/UnigineIGNetwork.h> /** * The sole purpose of this component is to have a callback called when this component is shutdown. * This can be useful if you need to be alerted when a node is being destroyed. */ class ShutdownComponent : public Unigine::Plugins::IG::NetworkComponentBase { public: COMPONENT(ShutdownComponent, Unigine::Plugins::IG::NetworkComponentBase); COMPONENT_SHUTDOWN(shutdown); void shutdown(); void setCallback(Unigine::CallbackBase* callback) { this->callback = callback; } Unigine::CallbackBase* getCallback() const { return callback; } PROP_NAME("ShutdownComponent"); PROP_PARAM(String, message, "", "Message", "If not empty, logs this message when the component is shut down"); private: Unigine::CallbackBase* callback = nullptr; }; #include "ShutdownComponent.h" using namespace Unigine; REGISTER_COMPONENT(ShutdownComponent) void ShutdownComponent::shutdown() { String msg = message.get(); if (!msg.empty()) Log::message("%s", msg.get()); if (callback) callback->run(); } 1
sityrax Posted November 17 Author Posted November 17 (edited) @Amerio.Stephane, Thanks for the answer! Apparently, i will use this solution. I also found static method: Node.AddCallback(Node.CALLBACK_INDEX.NODE_REMOVE, OnDestroy); But when node destroy event occured, unigine crashed with the message: "Unigine fatal error d:\ba\work\fb3821776bc41fe5\include\UnigineCallback.h:115: Assertion: '0 && 'Unigine::CallbackBase::run(): wrong size''" The documentation provides another event in Node instance API: Event<Node> EventNodeRemove But i can't find it in 2.17. Edited November 17 by sityrax
Recommended Posts