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. 오브젝트: 궁극의 경량 오브젝트로, 오리지널 오브젝트는 수동으로 메모리 관리를 하는데 사용해야 합니다. 말인 즉슨, 자체 맞춤 데이터 구조를 만드는 것이 그리 어렵지 않습니다, 심지어 맞춤 노드 구조도 만들 수 있는데 노드클래스보다 가볍죠.

    • 예시: 트리 노드를 참고하세요. 이 노드는 임의의 수의 행과 열이 있는 콘텐츠 테이블의 하이 레벨 맞춤 설정을 제공합니다. 시각화에 사용하는 데이터는 사실 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 클래스와 같은 다른 타입들. 각각은 저장되고 불러와 질 수 있습니다. 따라서 이들은 리소스에서 분화된 것들입니다.

    • 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.