Gmarquez Posted April 18, 2022 Share Posted April 18, 2022 Hi there! I need to know the actual lifeTimeMean of a particle system to modify it according another value but when I'm calling the method getLifeMean() I only get a value near to zero (9.99999997e-07) but the life time of the particle system is 5 as presetted in the node and I can see how the particles least a good amount of time. Did you have any hint of why I'm getting that near to zero value? Thanks. Link to comment
bmyagkov Posted April 19, 2022 Share Posted April 19, 2022 Hello! Can you share the code snippet where you used this method? Since on our side there is no issues and getLifeMean() returns exact the same value which was set in the editor: #include "AppWorldLogic.h" #include "UnigineObjects.h" #include "UnigineWorld.h" #include "UnigineEditor.h" // World logic, it takes effect only when the world is loaded. // These methods are called right after corresponding world script's (UnigineScript) methods. using namespace Unigine; AppWorldLogic::AppWorldLogic() { } AppWorldLogic::~AppWorldLogic() { } int AppWorldLogic::init() { // Write here code to be called on world initialization: initialize resources for your world scene during the world start. NodePtr node = Editor::get()->getNodeByName("ObjectParticles_0"); ObjectParticlesPtr p = ObjectParticles::cast(node); if (!p) { Log::error(" Can't find \'ObjectParticles_0\' node\n"); return 1; } float life_mean = p->getLifeMean(); Log::message("life mean %f \n", life_mean); return 1; } Thanks! Link to comment
Gmarquez Posted April 19, 2022 Author Share Posted April 19, 2022 (edited) Hi! Here it is the method where I'm using the call to the funciton void GroundMovement::updateTrails (Unigine::Math::Scalar cmdSpeed) { if (mTrailParticles.get != nullptr) { if (cmdSpeed != 0) { if (cmdSpeed > 0) { mTrailParticles->setDirection(Unigine::Math::vec3(0.0, -0.3, 0.0), Unigine::Math::vec3(0.0, 0.0, 1.0)); } else { mTrailParticles->setDirection(Unigine::Math::vec3(0.0, -0.3, 0.0), Unigine::Math::vec3(0.0, 0.0, 1.0)); } if (!mTrailParticles->isEmitterEnabled()) { mTrailParticles->setEmitterEnabled(1); } float inceaseFaactor = 1.0; float particleLifeTimePercent = Unigine::Math::abs (mTrailParticles->getLifeMen() * (mCommandSpeed / mSpeedData->getMasSpeed())) * increaseFactor; mTrailParticles->setLife(particleLifeTimePercent, mTrailParticles->getLifeSpread()); } else { mTrailParticles->setEmitterEnabled(0); } } } mTrailParticles is a member of the class defined as ObjectParticlesPtr and filled with Unigine::ObjectParticles::cast in an initializer method of the class I have attached a picture where you can see the execution stopped in a breakpoint just before to start the calculation of partcleLifeTimePercent and how the getLifeMean is returning the near to zero value. Sorry for the quality of the image, but the Intenet browser is in a Virtual Machine and I cant take screenshots of the IDE in a easier way Edited April 19, 2022 by Gmarquez Link to comment
cash-metall Posted April 20, 2022 Share Posted April 20, 2022 Hello! Does it happen on the first call this function or in the process of execution? you can try to debug this code with console Log::message("====== %d getLife mean before %f\n", mTrailParticles->getID(), mTrailParticles->getLifeMean()); float particleLifeTimePercent = Unigine::Math::abs (mTrailParticles->getLifeMean() * (mCommandSpeed / mSpeedData->getMasSpeed())) * increaseFactor; mTrailParticles->setLife(particleLifeTimePercent, mTrailParticles->getLifeSpread()); Log::message("====== %d getLife mean after %f\n", mTrailParticles->getID(), mTrailParticles->getLifeMean()); and show me the output of these messages? I also see that the direction vector is not normalized mTrailParticles->setDirection(Unigine::Math::vec3(0.0, -0.3, 0.0).normalize(), Unigine::Math::vec3(0.0, 0.0, 1.0)); Quote void setDirection(const Math::vec3 & dir, const Math::vec3 & up) Updates the direction vector of the node. By default, a direction vector points along -Z axis. This function changes its direction and reorients the node. Arguments const Math::vec3 & dir - New direction vector in the local space. The direction vector always has unit length. const Math::vec3 & up - New "up" vector in the local space. otherwise it will affect the scale of the object Link to comment
Gmarquez Posted April 20, 2022 Author Share Posted April 20, 2022 (edited) Hello! it is done in the process of the execution. This leadme to think in that point and the problem was that the LifeMean was being reduced every frame so it becomes zero. Thanks for notice me about the not normalized vector and for the help. Edit: But somthing wierd is happening, the node file have a life mean value of 10, but getLifeMean() is returning 5 in the first iteration Looks like this lifeMean = 5 is coming from another Actor Edited April 20, 2022 by Gmarquez Link to comment
cash-metall Posted April 20, 2022 Share Posted April 20, 2022 it looks like this code is called from another thread? maybe another thread changes? try to find all the places where the life of the particles can change... (I would not trust a debugger for multi-threaded work.) Link to comment
Recommended Posts