Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

ノードの使用をさけるべき場合といろいろな方法

ノードは安価に作成できますが、制限があります。プロジェクトには、すべてで処理を行う数万のノードが含まれている場合があります。ただし、動作が複雑になるほど、それぞれの負荷がプロジェクトのパフォーマンスに大きく影響します。

Godot には、ノードが使用するAPIを作成するための、より軽量なオブジェクトが用意されています。プロジェクトの機能を構築する方法を設計する際には、これらのオプションを念頭に置いてください。

  1. Object: 究極の軽量オブジェクトであり、オリジナルのオブジェクトは手動メモリ管理を使用する必要があります。そうは言っても、Node クラスよりも軽い独自のカスタムデータ構造、さらにはノード構造を作成することはそれほど難しくありません。

    • 例: Tree ノードを参照してください。任意の数の行と列を持つコンテンツテーブルの高度なカスタマイズをサポートします。ただし、視覚化の生成に使用するデータは、実際には TreeItem オブジェクトのツリーです。

    • Advantages: Simplifying one's API to smaller scoped objects helps improve its accessibility and improve iteration time. Rather than working with the entire Node library, one creates an abbreviated set of Objects from which a node can generate and manage the appropriate sub-nodes.

    注釈

    それらを扱うときは注意が必要です。オブジェクトを変数に保存できますが、これらの参照は警告なしに無効になる可能性があります。たとえば、オブジェクトの作成者がどこからでもオブジェクトを削除することを決定した場合、その次にオブジェクトにアクセスしたときにエラー状態が発生します。

  2. RefCounted: Only a little more complex than Object. They track references to themselves, only deleting loaded memory when no further references to themselves exist. These are useful in the majority of cases where one needs data in a custom class.

    • Example: See the FileAccess object. It functions just like a regular Object except that one need not delete it themselves.

    • 利点: オブジェクトと同じです。

  3. Resource: Only slightly more complex than RefCounted. They have the innate ability to serialize/deserialize (i.e. save and load) their object properties to/from Godot resource files.

    • 例: スクリプト、PackedScene(シーンファイル用)、および各 AudioEffect クラスのような他のタイプ。これらはそれぞれセーブおよびロードができるため、Resourceから拡張されます。

    • Advantages: Much has already been said on Resource's advantages over traditional data storage methods. In the context of using Resources over Nodes though, their main advantage is in Inspector-compatibility. While nearly as lightweight as Object/RefCounted, they can still display and export properties in the Inspector. This allows them to fulfill a purpose much like sub-Nodes on the usability front, but also improve performance if one plans to have many such Resources/Nodes in their scenes.