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