> 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/creator/content-creator-ko/sdk7/programming-patterns/mutable-data.md).

# 변경 가능한 데이터

컴포넌트에서 읽기 전용 및 변경 가능한 데이터를 처리하는 방법을 알아보세요

컴포넌트에서 데이터를 참조할 때 [컴포넌트](/creator/content-creator-ko/sdk7/architecture/entities-components.md), 변경 가능한 버전이나 읽기 전용(불변) 버전 중 하나를 가져올 수 있습니다.

가능하다면 항상 데이터의 읽기 전용 버전을 다루어야 합니다. 이 방법은 동일한 데이터의 변경 가능한 버전을 항상 다루는 것과 비교할 때, 씬의 성능을 매우 크게 향상시킬 수 있습니다.

그 `.get()` 함수는 컴포넌트의 읽기 전용(불변) 버전을 반환합니다. 값은 읽을 수만 있고, 그 위의 어떤 속성도 변경할 수 없습니다.

그 `.getMutable()` 함수는 해당 컴포넌트의 값을 변경할 수 있는 버전을 반환합니다. 컴포넌트를 변경할 계획이 있을 때만 변경 가능한 버전을 사용하고, 그렇지 않다면 항상 `get()`.

```ts
// 읽기 전용(불변) 버전을 가져옴
const immutableTransform = Transform.get(myEntity)

// 다음은 작동하지 않습니다:
// immutableTransform.position.y = 2

const mutableTransform = Transform.getMutable(myEntity)

// 다음 줄은 엔터티의 위치를 실제로 변경합니다
mutableTransform.position.y = 2
```

좋은 방법은 읽기 전용 컴포넌트를 순회하며 값을 확인한 뒤, 변경이 필요할 때만 개별 컴포넌트의 변경 가능한 버전을 가져오는 것입니다.

```ts
// 하드코딩된 최대 높이
const MAX_HEIGHT = 10

// 시스템 정의
function HeightLimitSystem(dt: number) {
	// Transform 컴포넌트가 있는 모든 엔터티를 순회
	for (const [entity] of engine.getEntitiesWith(Transform)) {
		// 읽기 전용 값 가져오기
		const currentHeight = Transform.get(entity).position.y

		// 값 비교
		if (currentHeight > MAX_HEIGHT) {
			// 변경을 위해 변경 가능한 버전 가져오기
			const mutableTransform = Transform.getMutable(entity)

			// 트랜스폼 변경
			mutableTransform.position.y = MAX_HEIGHT
		}
	}
}

// 시스템을 엔진에 추가
engine.addSystem(HeightLimitSystem)
```

위의 예시에서는 시스템이 엔터티의 `Transform` 컴포넌트를 검사합니다. 매 틱마다 위치의 *y* 가 하드코딩된 최대 높이보다 높은지 확인합니다. 트랜스폼의 높이가 이 한계를 넘는다면, 그때 그리고 그때만 Transform의 변경 가능한 버전을 가져옵니다. 이는 씬에 추가 작업처럼 보일 수 있지만, 게임 루프의 매 틱마다 값을 확인하고 변경은 가끔만 하는 씬에서는 엄청난 성능 향상을 가져옵니다.

이 관행은 다음의 원칙을 따릅니다 [데이터 지향 프로그래밍](/creator/content-creator-ko/sdk7/architecture/data-oriented-programming.md). 또한 이것이 가져오는 개선 효과가 워낙 크기 때문에 게임 업계에서 점차 업계 표준 관행으로 채택되고 있습니다.

{% hint style="warning" %}
**📔 참고**: SDK의 이전 버전(6.x 이하)에서는 컴포넌트가 항상 변경 가능한 것으로 취급되었습니다. 그 방식은 배우기는 조금 더 직관적일 수 있지만, 실행 효율은 훨씬 낮았습니다.
{% endhint %}


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.decentraland.org/creator/content-creator-ko/sdk7/programming-patterns/mutable-data.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
