> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/contributor/contributor-ko/scene-runtime/execution.md).

# 실행

런타임은 [장면들](https://github.com/decentraland/docs/tree/main/contributor/contributor/content/entity-types/scenes.md) 일반적인 Node 모듈처럼. 샌드박스가 설정되면(즉, 모든 [globals](https://github.com/decentraland/docs/tree/main/contributor/globals.md) 주입되고 [모듈](https://github.com/decentraland/docs/tree/main/contributor/modules.md) 로드할 준비가 되면), 씬의 코드가 평가되어 다음을 채울 수 있게 됩니다. [exports](https://github.com/decentraland/docs/tree/main/contributor/globals.md#module) 객체.

호스트는 다음에서 두 메서드를 가져옵니다: `exports`: [`onStart`](#onStart) (선택 사항) 및 [`onUpdate`](#onUpdate) (필수).

```ts
type Exports = {
  onStart?: () => Promise<void>;
  onUpdate: (deltaSeconds: number) => Promise<void>;
};
```

씬의 라이프사이클 동안 런타임은 이러한 메서드에 대한 호출이 동시에 이루어지지 않도록 보장합니다. 반환된 `Promise` 는 씬이 새 호출을 받기 전에 항상 await됩니다.

```mermaid
flowchart LR
    A[onStart] -->|await| B[onUpdate]
    B -->|await| B
```

{% hint style="info" %}
개별 씬과 게임 렌더링 엔진 간의 효과적이고 성능 좋은 동기화는 복잡한 문제입니다. Foundation의 구현에서 얻을 수 있는 교훈은 [ADR-148](https://adr.decentraland.org/adr/ADR-148).
{% endhint %}

**`onStart`**

씬의 라이프사이클은 비동기 `onStart` 메서드로 시작됩니다. 첫 호출 전에 완료되어야 하는 일회성 초기화를 수행하는 곳입니다. [`onUpdate`](#onUpdate) 이 이루어집니다.

```ts
onStart(): Promise<void>
```

씬은 이 호출을 사용해 런타임에서 기존 상태(예: 다음과 같은 것)를 요청하고 [기본 엔티티](https://github.com/decentraland/docs/tree/main/contributor/entities.md)) 및 자체 초기 설정을 수행해야 합니다.

내보내기는 `onStart` 모든 씬에 권장되며(SDK를 사용할 때는 자동으로 수행됨), 프로토콜상 필수는 아닙니다. 이 메서드는 없을 수도 있고, 즉시 해결되는 `Promise`.

**`onUpdate`**

씬이 सक्रिय하게 실행되는 동안, 비동기 `onUpdate` 메서드는 시간 경과를 보고하기 위해 런타임에 의해 주기적으로 호출됩니다. 이것이 씬의 핵심입니다. 각 연속 호출마다 엔티티를 업데이트하고, 입력을 처리하고, 애니메이션을 재생하고, 메시지를 보내고, UI를 표시하는 등의 작업을 할 수 있습니다.

```ts
onUpdate(deltaSeconds: number): Promise<void>
```

그 `deltaSeconds` 매개변수는 마지막 호출 이후 경과한 초의 소수입니다. `onUpdate` 는 런타임에 의해 시작된 시점부터의 것입니다(반환된 `Promise` 가 해결된 시점과는 무관합니다). 이는 각 실행 중인 씬에 고유합니다.

왜냐하면 `onUpdate` 호출이 절대 겹치지 않기 때문에, 다음의 순서는 `deltaSeconds` 일관된 타임라인을 생성합니다.

이상적인 상황에서는 씬이 실행될 기회를 얻어 `onUpdate` 각 프레임이 렌더링되기 전에 실행됩니다. 그러나 사용 가능한 리소스에 따라, 부하가 큰 씬은 자신의 `Promise` 을 다음 프레임까지 제때 완료하지 못할 수 있습니다. 이 점에서 각 씬은 독립적입니다. 다음의 경량 구현은 `onUpdate` 다른 씬의 하나의 오래 걸리는 호출과 같은 기간 동안 여러 번 호출될 수 있습니다.

참고 [ADR-148](https://adr.decentraland.org/adr/ADR-148) 자세한 내용은 참고하세요.

### 여러 씬 실행

World Explorer는 여러 개의 샌드박스 씬 실행을 지원할 뿐만 아니라, 항상 그렇게 동작해야 합니다. 그 이유는 두 가지입니다:

첫째, 플레이어가 세상을 탐험할 때 시야는 자신이 서 있는 씬의 지리적 경계를 넘어 확장됩니다. 플레이어가 볼 수 있어야 하는 콘텐츠를 생성하려면 가까운 씬(임의 또는 구성 가능한 거리까지)이 실행 중이어야 합니다.

둘째, 씬은 서로 겹치지 않는 자체 경계 안에서만 실행되는 것이 아닙니다. 서로 위에 겹쳐질 수도 있어, 플레이어 주변 영역에 영향을 주면서도 서로 다른 기능을 제공합니다.

특히 두 종류의 씬에서 그렇습니다: 아바타 씬과 휴대형 경험입니다.

#### 아바타 씬 <a href="#avatarscene" id="avatarscene"></a>

플레이어가 세계에 들어오는 순간부터, 다른 플레이어의 아바타를 렌더링하는 역할을 맡은 전역 씬이 실행되기 시작합니다.

이 씬은 지리적 경계에 제한되지 않으며, 플레이어의 위치와 상관없이 자신의 엔티티(및 커뮤니케이션용 UI 위젯)를 표시할 수 있습니다.

#### 휴대형 경험

Decentraland에서는 웨어러블이 자체 동작을 가질 수 있으며, 이는 별도의 씬 컨텍스트에서 실행됩니다. 이러한 씬은 플레이어를 중심으로 하며, 엔티티를 추가하거나 UI 위젯을 표시해 경험을 풍부하게 할 수 있습니다.

웨어러블을 착용하면 실행되기 시작하고, 제거하면 중지됩니다.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.decentraland.org/contributor/contributor-ko/scene-runtime/execution.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
