Unity performance Unity에 대한 성능 추천 사항 - Mixed Reality | Microsoft Docs

 Unity에 대한 성능 추천 사항 - Mixed Reality | Microsoft Docs

CPU 성능 추천 사항

아래 내용은 특히 Unity 및 C# 개발을 대상으로 하는 자세한 성능 사례에 대해 설명합니다.

캐시 참조

GetComponent<T>() 및 Camera.main과 같은 반복적인 함수 호출이 포인터를 저장하는 메모리 비용에 비해 더 비싸기 때문에 초기화 시 모든 관련 구성 요소 및 GameObjects에 대한 참조를 캐싱하는 것이 좋습니다. . Camera.main 은 아래의 FindGameObjectsWithTag() 만 사용합니다. 이는 "MainCamera" 태그를 사용하여 장면 그래프에서 카메라 개체를 검색하지만 많은 비용이 들어갑니다.

CS
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    private Camera cam;
    private CustomComponent comp;

    void Start() 
    {
        cam = Camera.main;
        comp = GetComponent<CustomComponent>();
    }

    void Update()
    {
        // Good
        this.transform.position = cam.transform.position + cam.transform.forward * 10.0f;

        // Bad
        this.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 10.0f;

        // Good
        comp.DoSomethingAwesome();

        // Bad
        GetComponent<CustomComponent>().DoSomethingAwesome();
    }
}

 참고


댓글

이 블로그의 인기 게시물

About AActor!!! "UObject" has no member "BeginPlay"

UNREAL Android build information

Shader informations nice blog ~ ~