ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ์ฃฝ๊ณ ๋‚˜์„œ, ๋‹ค์‹œ ๋„์ „ํ•˜๋Š” ๋ฐฉ์‹์„ ๊ธฐ์กด ์‹ ์—์„œ ์‹ ์„ ๋‹ค์‹œ ๋กœ๋“œํ•˜๋Š” ์‹์œผ๋กœ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

๋งˆ์šฐ์Šค ์ขŒํด๋ฆญ์„ ํ†ตํ•ด ์ด์„ ๋ฐœ์‚ฌํ•˜๋Š”๋ฐ ์ด ๋•Œ, ์ขŒํด๋ฆญ์˜ ์ธํ’‹์—‘์…˜์ด ์‹คํ–‰๋˜๊ณ , 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)


๋„์›€์„ ์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ฒ€์ƒ‰ํ•ด๋ณธ ๋ฐ”๋กœ๋Š” ์Šคํƒœํ‹ฑ ํด๋ž˜์Šค์—์„œ ๋ธ๋ฆฌ๊ฒŒ์ดํŠธ ๋“ฑ๋ก์ด ์‹  ์ „ํ™˜์‹œ ์˜ค๋ธŒ์ ํŠธ๋Š” ํŒŒ๊ดด๋˜๋‚˜, ๋ธ๋ฆฌ๊ฒŒ์ดํŠธ๋Š” ๋“ฑ๋กํ•ด์ œ๊ฐ€ ๋˜์ง€์•Š์•„์„œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค ๋“ค์–ด์„œ ์ผ๋‹จ ์ด๊ฒƒ์ €๊ฒƒ ์ฝ”๋“œ๋ฅผ ์—ด์‹ฌํžˆ ์ˆ˜์ •ํ•ด๋ณด๋Š”๋ฐ ์˜ค๋ฅ˜๊ฐ€ ์‚ฌ๋ผ์ง€์ง€ ์•Š์Šต๋‹ˆ๋‹ค.