ํ๋ ์ด์ด๊ฐ ์ฃฝ๊ณ ๋์, ๋ค์ ๋์ ํ๋ ๋ฐฉ์์ ๊ธฐ์กด ์ ์์ ์ ์ ๋ค์ ๋ก๋ํ๋ ์์ผ๋ก ๋ง๋ค์์ต๋๋ค.
๋ง์ฐ์ค ์ขํด๋ฆญ์ ํตํด ์ด์ ๋ฐ์ฌํ๋๋ฐ ์ด ๋, ์ขํด๋ฆญ์ ์ธํ์์ ์ด ์คํ๋๊ณ , PlayerController์์ ์๋ ์ฝ๋๊ฐ ์คํ์ด ๋ฉ๋๋ค.
์ ์ ๋ค์ ๋ก๋๋ฅผํ๊ณ ๋์,ย ์ขํด๋ฆญ์ ํ๋ฉด, ์ฒ์ ์ ์ ๋ก๋ํ์๋์ ๋ค๋ฅด๊ฒย ๋๊ฐ์ง์ย missingreferenceexception ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. ๊ทธ๋ฐ๋ฐ ์ด์ํ๊ฒ๋ ์๋(์ด ๋ฐ์ฌ)์ ์ฒซ๋ฒ์งธ ๋ก๋ํ์๋์ ๋ค๋ฅผ ๊ฒ ์์ดย ์๋ฉ๋๋ค.
์ค๋ฅ๊ฐ ๋ฐ์ํ๋ ๋ถ๋ถ์ "PlayerController"cs(์ฑ๊ธํค์ผ๋ก ๊ตฌํ)๊ณผย ์ธํ์์ ์ ๋๋ค.
์ฒซ๋ฒ์งธ ์ค๋ฅ๋ก๊ทธ์์ ๊ฐ๋ฅดํค๋ ์ฝ๋๋ย "PlayerController"๊ฐ ์์๋ฐ์ class์์ GetComponent๋ฅผ ํตํด "ํ๋ ์ด์ด ์ปจํธ๋กค๋ฌ ์ปดํฌ๋ํธ"(์คํฌ๋ฆฝํธ)๊ฐ ์๋ย
"ํ๋ ์ด์ด" ๊ฒ์ ์ค๋ธ์ ํธ์ ์ปดํฌ๋ํธ๋ฅผ ์ป์ ๋์ ๋๋ค. ๋์ถฉ ์๋์ ์ฝ๋์ ๋๋ค.
public virtual T GetState<T>() where T : State
ย ย {
ย ย ย ย T t = GetComponent<T>();
ย ย ย ย return t;
ย ย }
๊ทธ๋ฆฌ๊ณ ์ฒซ๋ฒ์งธ ์ค๋ฅ๋ก๊ทธ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
MissingReferenceException: The object of type 'PlayerController' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.Component.GetComponent[T] () (at <685c48cf8f0b48abb797275c046dda6a>:0)
StateMachine.GetState[T] () (at Assets/Scripts/Unit/Both/State/StateMachine.cs:24)
StateMachine.ChangeState[T] () (at Assets/Scripts/Unit/Both/State/StateMachine.cs:31)
IdleState.OnUseWeaponState (UnityEngine.InputSystem.InputAction+CallbackContext obj) (at Assets/Scripts/Unit/Player/State/IdleState.cs:37)
UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe[TValue] (UnityEngine.InputSystem.Utilities.CallbackArray`1[System.Action`1[TValue]]& callbacks, TValue argument, System.String callbackName, System.Object context) (at Library/PackageCache/com.unity.inputsystem@1.4.4/InputSystem/Utilities/DelegateHelpers.cs:46)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)
๋๋ฒ์งธ ์ค๋ฅ๋ก๊ทธ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
MissingReferenceException while executing 'performed' callbacks of 'Player/Weapon[/Mouse/leftButton]'
UnityEngine.InputSystem.LowLevel.NativeInputRuntime/<>c__DisplayClass7_0:<set_onUpdate>b__0 (UnityEngineInternal.Input.NativeInputUpdateType,UnityEngineInternal.Input.NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate (UnityEngineInternal.Input.NativeInputUpdateType,intptr)
๋๊ฐ ๋งํ๋๋ก ์ฑ๊ธํดA๊ฐ์ฒด์๊ฒ ์ฑ๊ธํด์๋B๊ฐ์ฒด๊ฐ ๋ธ๋ฆฌ๊ฒ์ดํธ๋ฅผ ๋ฑ๋กํ์ผ๋ฉด, B๊ฐ ์ฌ๋ผ์ง๋ฉด ํด๋น ๋ธ๋ฆฌ๊ฒ์ดํธ๋ ๋นผ์ค์ผ ํจ. ์๊ทธ๋ผ ์ ๋ฐ ๋ฌธ์ ๊ฐ ๋ฐ์ํจ. ์ด๋ฏธ ํด๊ฒฐ๋ฒ์ ์๊ณ ์๋๊ฑฐ๊ฐ์๋ฐ ๋ญ๋์์ดํ์ํ๋ค๋๊ฑฐ์
์ค๋ฅ ํด๊ฒฐํ์ต๋๋ค ใ ์๊ฐ์ํ ์คํฌ๋ฆฝํธ์์ ๋ธ๋ฆฌ๊ฒ์ดํธ๊ฐ ์์ด์, ๊ทธ ์น๊ตฌ๊ฐ ๋ฌธ์ ์๋ค์ ๊ฐ์ฌํฉ๋๋ค ๋ต๋ณ