Godot4 デバッガーモニターの情報を出力するスクリプト例

無料・軽快な 2D / 3D 用のゲームエンジン Godot Engine 4 で、メモリ・オブジェクト・リソースなどのリアルタイムの使用量を表示できるデバッガーのモニターの GUI の情報を、スクリプト取得して print 出力するスクリプト例とその結果を紹介します。

※ GodotEngine 4.3 を使用しています。.NET 版ではありません。
※スクリプトは自己責任でご使用ください。

Performance.get_monitor 関数

GodotEngine4 のエディタのデバッガーボトムパネルのモニタータブで、モニターしたい項目をチェックするとその項目のグラフが表示され、現在のメモリ使用量などを確認できます。

Godot4 デバッガーのモニターによるメモリ使用量などの確認

get_monitor 関数の引数で指定したモニターの項目の値を取得することができます。

Returns the value of one of the available built-in monitors. You should provide one of the Monitor constants as the argument, like this:

使用可能な組み込みモニターのいずれかの値を返します。次のように、Monitor 定数の 1 つを引数として指定する必要があります。
print(Performance.get_monitor(Performance.TIME_FPS)) # Prints the FPS to the console.

See get_custom_monitor to query custom performance monitors’ values.

Performance — Godot Engine (4.x)の日本語のドキュメント #get_monitor と Google 翻訳

デバッガーのモニターの情報を辞書として返す自作関数

デバッガーのモニターの情報を辞書として返す自作関数は以下です。
※詳細は、スクリプト内のコメントを参照してください。

## Performance.Monitor に登録されている列挙子に関するパフォーマンスの情報を辞書に記録して返します。
## TODO: NAVIGATION_OBSTACLE_COUNT など 4.4 から利用可能な値についてはコメントを解除して使用してください。
static func get_moniter_info() -> Dictionary:
	var monitor_info = {}
	monitor_info["TIME_FPS"] = Performance.get_monitor(Performance.Monitor.TIME_FPS)
	monitor_info["TIME_PROCESS"] = Performance.get_monitor(Performance.Monitor.TIME_PROCESS)
	monitor_info["TIME_PHYSICS_PROCESS"] = Performance.get_monitor(Performance.Monitor.TIME_PHYSICS_PROCESS)
	monitor_info["TIME_NAVIGATION_PROCESS"] = Performance.get_monitor(Performance.Monitor.TIME_NAVIGATION_PROCESS)
	monitor_info["MEMORY_STATIC"] = Performance.get_monitor(Performance.Monitor.MEMORY_STATIC)
	monitor_info["MEMORY_STATIC_MAX"] = Performance.get_monitor(Performance.Monitor.MEMORY_STATIC_MAX)
	monitor_info["MEMORY_MESSAGE_BUFFER_MAX"] = Performance.get_monitor(Performance.Monitor.MEMORY_MESSAGE_BUFFER_MAX)
	monitor_info["OBJECT_COUNT"] = Performance.get_monitor(Performance.Monitor.OBJECT_COUNT)
	monitor_info["OBJECT_RESOURCE_COUNT"] = Performance.get_monitor(Performance.Monitor.OBJECT_RESOURCE_COUNT)
	monitor_info["OBJECT_NODE_COUNT"] = Performance.get_monitor(Performance.Monitor.OBJECT_NODE_COUNT)
	monitor_info["OBJECT_ORPHAN_NODE_COUNT"] = Performance.get_monitor(Performance.Monitor.OBJECT_ORPHAN_NODE_COUNT)
	monitor_info["RENDER_TOTAL_OBJECTS_IN_FRAME"] = Performance.get_monitor(Performance.Monitor.RENDER_TOTAL_OBJECTS_IN_FRAME)
	monitor_info["RENDER_TOTAL_PRIMITIVES_IN_FRAME"] = Performance.get_monitor(Performance.Monitor.RENDER_TOTAL_PRIMITIVES_IN_FRAME)
	monitor_info["RENDER_TOTAL_DRAW_CALLS_IN_FRAME"] = Performance.get_monitor(Performance.Monitor.RENDER_TOTAL_DRAW_CALLS_IN_FRAME)
	monitor_info["RENDER_VIDEO_MEM_USED"] = Performance.get_monitor(Performance.Monitor.RENDER_VIDEO_MEM_USED)
	monitor_info["RENDER_TEXTURE_MEM_USED"] = Performance.get_monitor(Performance.Monitor.RENDER_TEXTURE_MEM_USED)
	monitor_info["RENDER_BUFFER_MEM_USED"] = Performance.get_monitor(Performance.Monitor.RENDER_BUFFER_MEM_USED)
	monitor_info["PHYSICS_2D_ACTIVE_OBJECTS"] = Performance.get_monitor(Performance.Monitor.PHYSICS_2D_ACTIVE_OBJECTS)
	monitor_info["PHYSICS_2D_COLLISION_PAIRS"] = Performance.get_monitor(Performance.Monitor.PHYSICS_2D_COLLISION_PAIRS)
	monitor_info["PHYSICS_2D_ISLAND_COUNT"] = Performance.get_monitor(Performance.Monitor.PHYSICS_2D_ISLAND_COUNT)
	monitor_info["PHYSICS_3D_ACTIVE_OBJECTS"] = Performance.get_monitor(Performance.Monitor.PHYSICS_3D_ACTIVE_OBJECTS)
	monitor_info["PHYSICS_3D_COLLISION_PAIRS"] = Performance.get_monitor(Performance.Monitor.PHYSICS_3D_COLLISION_PAIRS)
	monitor_info["PHYSICS_3D_ISLAND_COUNT"] = Performance.get_monitor(Performance.Monitor.PHYSICS_3D_ISLAND_COUNT)
	monitor_info["AUDIO_OUTPUT_LATENCY"] = Performance.get_monitor(Performance.Monitor.AUDIO_OUTPUT_LATENCY)
	monitor_info["NAVIGATION_ACTIVE_MAPS"] = Performance.get_monitor(Performance.Monitor.NAVIGATION_ACTIVE_MAPS)
	monitor_info["NAVIGATION_REGION_COUNT"] = Performance.get_monitor(Performance.Monitor.NAVIGATION_REGION_COUNT)
	monitor_info["NAVIGATION_AGENT_COUNT"] = Performance.get_monitor(Performance.Monitor.NAVIGATION_AGENT_COUNT)
	monitor_info["NAVIGATION_LINK_COUNT"] = Performance.get_monitor(Performance.Monitor.NAVIGATION_LINK_COUNT)
	monitor_info["NAVIGATION_POLYGON_COUNT"] = Performance.get_monitor(Performance.Monitor.NAVIGATION_POLYGON_COUNT)
	monitor_info["NAVIGATION_EDGE_COUNT"] = Performance.get_monitor(Performance.Monitor.NAVIGATION_EDGE_COUNT)
	monitor_info["NAVIGATION_EDGE_MERGE_COUNT"] = Performance.get_monitor(Performance.Monitor.NAVIGATION_EDGE_MERGE_COUNT)
	monitor_info["NAVIGATION_EDGE_CONNECTION_COUNT"] = Performance.get_monitor(Performance.Monitor.NAVIGATION_EDGE_CONNECTION_COUNT)
	monitor_info["NAVIGATION_EDGE_FREE_COUNT"] = Performance.get_monitor(Performance.Monitor.NAVIGATION_EDGE_FREE_COUNT)
	# 4.4 から
	#monitor_info["NAVIGATION_OBSTACLE_COUNT"] = Performance.get_monitor(Performance.Monitor.NAVIGATION_OBSTACLE_COUNT)
	#monitor_info["PIPELINE_COMPILATIONS_CANVAS"] = Performance.get_monitor(Performance.Monitor.PIPELINE_COMPILATIONS_CANVAS)
	#monitor_info["PIPELINE_COMPILATIONS_MESH"] = Performance.get_monitor(Performance.Monitor.PIPELINE_COMPILATIONS_MESH)
	#monitor_info["PIPELINE_COMPILATIONS_SURFACE"] = Performance.get_monitor(Performance.Monitor.PIPELINE_COMPILATIONS_SURFACE)
	#monitor_info["PIPELINE_COMPILATIONS_DRAW"] = Performance.get_monitor(Performance.Monitor.PIPELINE_COMPILATIONS_DRAW)
	#monitor_info["PIPELINE_COMPILATIONS_SPECIALIZATION"] = Performance.get_monitor(Performance.Monitor.PIPELINE_COMPILATIONS_SPECIALIZATION)

	return monitor_info

テスト

メニュー「シーン」→新規シーン」を選択してから、シーンドックで「インターフェース」を選択して Control ルートノードを作成したあと、それに以下のスクリプトを割り当てF6 キーで現在のシーンを実行してください。

extends Control


# Called when the node enters the scene tree for the first time.
func _ready():
	# モニターの情報を辞書で取得します。キーは Performance.Monitor の列挙子です。
	var monitor_info: Dictionary = ScUtil.get_moniter_info()
	# モニターの情報をタブや改行で整形して出力します。
	print(ScUtil.to_pretty_print_string(monitor_info))
	return

配列と辞書のデータを見やすい形式に変換する自作関数 to_pretty_print_string については以下の記事を参照してください。

F6 キーなどで、先ほどのテスト用スクリプトを割り当てたシーンを実行すると、以下のように、 _ready が呼ばれた時点のモニター可能な情報取得できました。

Godot Engine v4.3.stable.official.77dcf97d8 - https://godotengine.org
OpenGL API 3.3.0 NVIDIA 536.67 - Compatibility - Using Device: NVIDIA - NVIDIA GeForce RTX 4060

{
	"TIME_FPS": 1,
	"TIME_PROCESS": 0,
	"TIME_PHYSICS_PROCESS": 0,
	"TIME_NAVIGATION_PROCESS": 0,
	"MEMORY_STATIC": 53119514,
	"MEMORY_STATIC_MAX": 54885330,
	"MEMORY_MESSAGE_BUFFER_MAX": 4096,
	"OBJECT_COUNT": 1290,
	"OBJECT_RESOURCE_COUNT": 3,
	"OBJECT_NODE_COUNT": 3,
	"OBJECT_ORPHAN_NODE_COUNT": 0,
	"RENDER_TOTAL_OBJECTS_IN_FRAME": 0,
	"RENDER_TOTAL_PRIMITIVES_IN_FRAME": 0,
	"RENDER_TOTAL_DRAW_CALLS_IN_FRAME": 0,
	"RENDER_VIDEO_MEM_USED": 10143268,
	"RENDER_TEXTURE_MEM_USED": 3738268,
	"RENDER_BUFFER_MEM_USED": 6405000,
	"PHYSICS_2D_ACTIVE_OBJECTS": 0,
	"PHYSICS_2D_COLLISION_PAIRS": 0,
	"PHYSICS_2D_ISLAND_COUNT": 0,
	"PHYSICS_3D_ACTIVE_OBJECTS": 0,
	"PHYSICS_3D_COLLISION_PAIRS": 0,
	"PHYSICS_3D_ISLAND_COUNT": 0,
	"AUDIO_OUTPUT_LATENCY": 0.00999999977648,
	"NAVIGATION_ACTIVE_MAPS": 0,
	"NAVIGATION_REGION_COUNT": 0,
	"NAVIGATION_AGENT_COUNT": 0,
	"NAVIGATION_LINK_COUNT": 0,
	"NAVIGATION_POLYGON_COUNT": 0,
	"NAVIGATION_EDGE_COUNT": 0,
	"NAVIGATION_EDGE_MERGE_COUNT": 0,
	"NAVIGATION_EDGE_CONNECTION_COUNT": 0,
	"NAVIGATION_EDGE_FREE_COUNT": 0
}

--- Debugging process stopped ---

まとめ

今回は、無料・軽快な 2D / 3D 用のゲームエンジン Godot Engine 4 で、メモリ・オブジェクト・リソースなどのリアルタイムの使用量を表示できるデバッガーのモニターの GUI の情報を、スクリプト取得して print 出力するスクリプト例とその結果を紹介しました。

参照サイト Thank You!

記事一覧 → Compota-Soft-Press

コメント

Ads Blocker Image Powered by Code Help Pro

お願い - Ads Blocker Detected

このサイトは広告を掲載して運営しています。

ポップアップを閉じて閲覧できますが、よろしければ

このサイト内の広告を非表示にする拡張機能をオフにしていただけませんか?

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

タイトルとURLをコピーしました