• 카테고리

    질문 & 답변
  • 세부 분야

    게임 프로그래밍

  • 해결 여부

    미해결

nullpointexception 에러가 뜹니다.

23.07.18 23:27 작성 조회수 268

0

2시간동안 이리저리 따라해서 계속 널포인트가 뜹니다.

PlayerController클레스의 여기에서 널포인트가 뜹니다.

Managers.Input.KeyAction += OnKeyboard;

 

에러내용은 아래이고

NullReferenceException: Object reference not set to an instance of an object

Managers.get_Input () (at Assets/Script/Managers/Managers.cs:11)

PlayerController.Start () (at Assets/Script/PlayerController.cs:1PlayerController.PNGManagers.PNG2)

답변 2

·

답변을 작성해보세요.

0

prokimssam님의 프로필

prokimssam

2023.08.12

Managers 클래스에서
private static void Init()
{
if (s_instance == null)
{
GameObject go = GameObject.Find("@Managers");
if (go == null)
{
go = new GameObject { name = "@Managers" };
go.AddComponent<Managers>();
}
DontDestroyOnLoad(go); //<== 여기 부분
s_instance = go.GetComponent<Managers>(); //<== 여기 부분
}

 

아래 두 줄 괄호 위치 잘 확인해 보세요~

저도 그랬어요~~ ^^
}

0

s_instance 가 NULL이라면, 원래 그 아이를 채워주는 부분이 어딘지를 찾아보시면 됩니다.
현재 그 부분이 누락되어 있네요. (Hint : Managers)