diff --git a/doc/classes/Performance.xml b/doc/classes/Performance.xml
index 4ee43d57608..f40de6625e3 100644
--- a/doc/classes/Performance.xml
+++ b/doc/classes/Performance.xml
@@ -57,58 +57,61 @@
Number of resources currently used.
- Number of nodes currently instanced. This also includes the root node, as well as any nodes not in the scene tree.
+ Number of nodes currently instanced in the scene tree. This also includes the root node.
-
+
+ Number of instanced nodes that aren't included in the scene tree.
+
+
3D objects drawn per frame.
-
+
Vertices drawn per frame. 3D only.
-
+
Material changes per frame. 3D only
-
+
Shader changes per frame. 3D only.
-
+
Render surface changes per frame. 3D only.
-
+
Draw calls per frame. 3D only.
-
+
Video memory used. Includes both texture and vertex memory.
-
+
Texture memory used.
-
+
Vertex memory used.
-
+
-
+
Number of active [RigidBody2D] nodes in the game.
-
+
Number of collision pairs in the 2D physics engine.
-
+
Number of islands in the 2D physics engine.
-
+
Number of active [RigidBody] and [VehicleBody] nodes in the game.
-
+
Number of collision pairs in the 3D physics engine.
-
+
Number of islands in the 3D physics engine.
-
+
-
+
diff --git a/main/performance.cpp b/main/performance.cpp
index 2f7ebf76564..66184518948 100644
--- a/main/performance.cpp
+++ b/main/performance.cpp
@@ -32,6 +32,7 @@
#include "core/message_queue.h"
#include "core/os/os.h"
+#include "scene/main/node.h"
#include "scene/main/scene_tree.h"
#include "servers/audio_server.h"
#include "servers/physics_2d_server.h"
@@ -55,6 +56,7 @@ void Performance::_bind_methods() {
BIND_ENUM_CONSTANT(OBJECT_COUNT);
BIND_ENUM_CONSTANT(OBJECT_RESOURCE_COUNT);
BIND_ENUM_CONSTANT(OBJECT_NODE_COUNT);
+ BIND_ENUM_CONSTANT(OBJECT_ORPHAN_NODE_COUNT);
BIND_ENUM_CONSTANT(RENDER_OBJECTS_IN_FRAME);
BIND_ENUM_CONSTANT(RENDER_VERTICES_IN_FRAME);
BIND_ENUM_CONSTANT(RENDER_MATERIAL_CHANGES_IN_FRAME);
@@ -76,6 +78,14 @@ void Performance::_bind_methods() {
BIND_ENUM_CONSTANT(MONITOR_MAX);
}
+float Performance::_get_node_count() const {
+ MainLoop *ml = OS::get_singleton()->get_main_loop();
+ SceneTree *sml = Object::cast_to(ml);
+ if (!sml)
+ return 0;
+ return sml->get_node_count();
+}
+
String Performance::get_monitor_name(Monitor p_monitor) const {
ERR_FAIL_INDEX_V(p_monitor, MONITOR_MAX, String());
@@ -92,6 +102,7 @@ String Performance::get_monitor_name(Monitor p_monitor) const {
"object/objects",
"object/resources",
"object/nodes",
+ "object/orphan_nodes",
"raster/objects_drawn",
"raster/vertices_drawn",
"raster/mat_changes",
@@ -128,14 +139,8 @@ float Performance::get_monitor(Monitor p_monitor) const {
case MEMORY_MESSAGE_BUFFER_MAX: return MessageQueue::get_singleton()->get_max_buffer_usage();
case OBJECT_COUNT: return ObjectDB::get_object_count();
case OBJECT_RESOURCE_COUNT: return ResourceCache::get_cached_resource_count();
- case OBJECT_NODE_COUNT: {
-
- MainLoop *ml = OS::get_singleton()->get_main_loop();
- SceneTree *sml = Object::cast_to(ml);
- if (!sml)
- return 0;
- return sml->get_node_count();
- };
+ case OBJECT_NODE_COUNT: return _get_node_count();
+ case OBJECT_ORPHAN_NODE_COUNT: return Node::orphan_node_count;
case RENDER_OBJECTS_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_OBJECTS_IN_FRAME);
case RENDER_VERTICES_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_VERTICES_IN_FRAME);
case RENDER_MATERIAL_CHANGES_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_MATERIAL_CHANGES_IN_FRAME);
diff --git a/main/performance.h b/main/performance.h
index 850c4c2d523..912e005c531 100644
--- a/main/performance.h
+++ b/main/performance.h
@@ -43,6 +43,8 @@ class Performance : public Object {
static Performance *singleton;
static void _bind_methods();
+ float _get_node_count() const;
+
float _process_time;
float _physics_process_time;
@@ -60,6 +62,7 @@ public:
OBJECT_COUNT,
OBJECT_RESOURCE_COUNT,
OBJECT_NODE_COUNT,
+ OBJECT_ORPHAN_NODE_COUNT,
RENDER_OBJECTS_IN_FRAME,
RENDER_VERTICES_IN_FRAME,
RENDER_MATERIAL_CHANGES_IN_FRAME,
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 5f9c187e0b8..cddf4db2e88 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -41,6 +41,8 @@
VARIANT_ENUM_CAST(Node::PauseMode);
+int Node::orphan_node_count = 0;
+
void Node::_notification(int p_notification) {
switch (p_notification) {
@@ -84,11 +86,14 @@ void Node::_notification(int p_notification) {
add_to_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_id()));
get_tree()->node_count++;
+ orphan_node_count--;
} break;
case NOTIFICATION_EXIT_TREE: {
get_tree()->node_count--;
+ orphan_node_count++;
+
if (data.input)
remove_from_group("_vp_input" + itos(get_viewport()->get_instance_id()));
if (data.unhandled_input)
@@ -2938,6 +2943,8 @@ Node::Node() {
data.use_placeholder = false;
data.display_folded = false;
data.ready_first = true;
+
+ orphan_node_count++;
}
Node::~Node() {
@@ -2948,6 +2955,8 @@ Node::~Node() {
ERR_FAIL_COND(data.parent);
ERR_FAIL_COND(data.children.size());
+
+ orphan_node_count--;
}
////////////////////////////////
diff --git a/scene/main/node.h b/scene/main/node.h
index b490db37c51..9b9ca064554 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -75,6 +75,8 @@ public:
bool operator()(const Node *p_a, const Node *p_b) const { return p_b->data.process_priority == p_a->data.process_priority ? p_b->is_greater_than(p_a) : p_b->data.process_priority > p_a->data.process_priority; }
};
+ static int orphan_node_count;
+
private:
struct GroupData {