문제
GameManager를 싱글톤으로 선언할 때 FindObjectOfType을 사용했었는데 더이상 사용되지않는다는 경고가 발생했다.
warning CS0618: 'Object.FindObjectOfType(Type)' is obsolete:
'Object.FindObjectOfType has been deprecated.
Use Object.FindFirstObjectByType instead or if finding any instance is acceptable the faster Object.
FindAnyObjectByType'
자세하게 마우스를 올려보니 이런식으로 나와있다.
Alt+Enter를 이용해서 경고를 해결하려 하면
[System.Obsolete]가 추가되는데 이건 추후 글로 쓰겠다.
일단은 베르님 블로그 참고
[C#] Attribute : Obsolete - 더 이상 사용하지 않거나 그럴 예정인 코드에 대해서
프로그래밍을 할 때 있어서 모든 일이 처음 설계한대로 흘러간다면 얼마나 좋을까? 하지만 Hello World를 출럭하는 프로그램이 아닌 이상에야 그런 일은 있을 수 없다. 확장성을 위해, 재사용성을
wergia.tistory.com
나는 이렇게 사용하지않고 다른 함수로 바꿔줄 것이다.
해결 방법
둘 중 한가지로 바꿔주면 된다
FindAnyObjectByType
>> 유니티 공식글 참고
Unity - Scripting API: Object.FindAnyObjectByType
Object.FindAnyObjectByType doesn't return Assets (for example meshes, textures, or prefabs), or inactive objects. It also doesn't return objects that have HideFlags.DontSave set. Note: The object that this function returns isn't guaranteed to be the same b
docs.unity3d.com
FindFirstObjectByType
>> 유니티 공식글 참고
Unity - Scripting API: Object.FindFirstObjectByType
Object.FindFirstObjectByType doesn't return Assets (for example meshes, textures, or prefabs), or inactive objects. It also doesn't return objects that have HideFlags.DontSave set. Note: This function is very resource intensive. It's best practice to not u
docs.unity3d.com
그럼 요렇게 경고 밑줄이 사라진 것을 볼 수 있따!
헤헤
모두 도움이 됐으면 좋겠당.
'Unity > Tip' 카테고리의 다른 글
[Unity] SDK Build-tools component is not found 오류 (4) | 2024.09.26 |
---|---|
[Unity] 컴파일 시간 단축시키기 (0) | 2024.06.17 |
[Unity] Aseprite: Animation Importer 에셋 (1) | 2023.12.02 |
[Unity] 유니티 씬뷰 오브젝트 클릭 안되는 오류(하이러키창에서만 선택되는 오류) (0) | 2023.11.26 |
[Unity] 유니티 UI 테두리 모서리 둥글게 주기(+깃 사용해서 패키지 다운받기) (0) | 2023.11.25 |