Hmmm that is quite bad I would rather say, I guess one more reason to add unit testing or something like that. Anyhow what is solution should I downgrade to 3.7 something?
what is RunningGameScreen ? A scene ? Node? something that should be a part of a Scene?
If RunningGameScreen is a Node (or subclass) that is going to be part of the very first scene, then getRunningScene will return nullptr because there is no running scene at that point.
@slackmoehrle runWithScene() is not an immediate operation. It will take effect on the next frame. getRunningScene returns the current running scene, and not the one that is scheduled to run in the next frame.
Thanks for responding, so according to you getRunningScene only works once a frame has been output right and before that first frame method won’t work and proper way to get it is to use node->getScene()
long answer: no. getRunningScene always work. The thing is that runWithScene() does not immediately run a scene. So there is no running scene right after calling runWithScene()… you have to wait one frame.
node->getScene() returns null as well
I use this->getScene() this returned null. I think that first frame issue may be the reason as well in this case as well.
Node::getScene() is different. It will return the root node of the hierarchy dynamically cast as a Scene. So if a Node has been added to a hierarchy that has a Scene as it’s root then getScene() will return that scene object regardless of whether it’s running or not. As Node::addChild() is immediate, this function will always return what you expect.
Scene* Node::getScene() const
{
if (!_parent)
return nullptr;
auto sceneNode = _parent;
while (sceneNode->_parent)
{
sceneNode = sceneNode->_parent;
}
return dynamic_cast<Scene*>(sceneNode);
}