보키_기록용

GetController()와 GetPlayerController()의 차이 본문

언리얼/MEMO

GetController()와 GetPlayerController()의 차이

bokki0117 2022. 10. 24. 10:25

ACharacter를 상속한 파생클래스의 BeginPlay에서 GetController()는 nullptr를 반환하고 GetPlayerController()는 제대로 반환되어서 둘의 차이를 알아보고자 한다.

 

PlayerController가 Controller의 자식이지만, BeginPlay 시점에서 Controller가 캐릭터의 소유 상태가 아닐 수도 있다. (호출 시점에 따라 다르다.) 처음 게임 시작 시 PlayerContoller와 PlayerState 객체를 얻을때, 이 시점에서 캐릭터는 없지만 PlayerController가 UI를 처리하므로 로그인 위젯 등을 수행할 수 있다. 어느 시점에서 게임 모드가 캐릭터를 생성하고 BeginPlay를 실행하며, 다시 여기에 컨트롤러가 아직 설정되어 있지 않다. 캐릭터 (폰)가 PlayerController에 의해 소유 된 직후 GetController ()로 액세스 할 수 있다. 

 

PlayerController가 Controller의 자식이지만 (로그인 등시 null이 아님), Controller는 캐릭터가 소유되지 않는 한 캐릭터의 POV에서 여전히 null이 될 수 있다.

 

GetController() returns nullptr while GetPlayerController() works properly - Programming & Scripting / C++ - Unreal Engine Forums

 

GetController() returns nullptr while GetPlayerController() works properly

The documentation is mostly a collection of header comments, better is to actually take some time to read the engine code for the functions. As you get into networking/multiplayer with controllers things get even more complex. The best networking documenta

forums.unrealengine.com

 

Comments