Unity

Instantiate

JunOnJuly 2023. 11. 9. 00:38
728x90

Instantiate


개념

Object를 인스턴스화해서 복제하는 명령어입니다. 일반적으로 프리팹을 복제해 인스턴트화 할 때 많이 사용합니다.


함수

public static Object Instantiate(Object original, Vector3 position, Quaternion rotation, Transform parent);

의 형태를 띄며 Object original 을 제외한 인자는 필요할 때 사용하시면 됩니다.

 

original An existing object that you want to make a copy of. : 일반적으로 복제하고자 하는 prefab 입니다.
position Position for the new object. : 새로 생성될 개체의 위치입니다.
rotation Orientation of the new object. : 새로 생성될 개체의 방향입니다.
parent Parent that will be assigned to the new object. : 새로 생성될 개체를 삽입할 부모입니다.
instantiateInWorldSpace When you assign a parent Object, pass true to position the new object directly in world space. Pass false to set the Object’s position relative to its new parent.
Parent 개체를 할당할 때 전달하는 bool 값으로 true 이면 새로운 개체를 월드 공간에 직접 배치하겠다는 뜻이고 false 이면 Parent 와 상대적으로 설정하겠다는 뜻입니다.

출처 : https://docs.unity3d.com/ScriptReference/Object.Instantiate.html


주의사항 

  • Unity 는 StackOverflow를 방지하고자 스택사이즈의 절반이 가득차게 되면 InsufficientExecutionStackException 을 일으킵니다.
  • 복제시 Activate 상태도 적용됩니다. 원본 Object 가 Active 상태라면 복제된 Object 도 Active 상태가 적용됩니다.
  • Parent 인자가 사용되고 Position과 Rotation이 지정되지 않은 경우에는 Original Object의 Position과 Rotation이 복제된 Object의 Local Position과 Rotation으로 사용된다.
  • InstantiateInWorldSpace 인자가 true인 경우에는 월드 공간에서의 Position과 Rotation이 사용된다.
728x90

'Unity' 카테고리의 다른 글

게임 시점  (0) 2023.11.10
transform.position 와 rigidbody.position 의 차이  (2) 2023.11.09
PlayerPrefs (플레이어 프리팹)  (0) 2023.11.07
Unity  (0) 2023.11.04