0

現在、Unreal Engine 4 で最初のクラスを開発しています。UScript を広範囲に使用しているため、純粋な C++ で型キャストがどのように機能するかについて少し混乱しています。より具体的には、クラス/オブジェクトのキャストです。

現在、MyCustomPlayerControllerVariable の MyCustomPlayerController を呼び出す MyCustomGameMode に switch ステートメントをまとめています。

私がオーバーライドしている問題の関数は次のとおりです。virtual UClass* GetDefaultPawnClassForController(AController* InController);

現在、次のコード行で変数を呼び出そうとしていますが、これが間違っていることはわかっていますが、理由はわかりません。

Cast<MyCustomPlayerController>(InController).MyCustomPlayerControllerVariable

「InController」を MyCustomPlayerController にキャストすることに興味がありますが、Cast<MyCustomPlayerController>(InController)うまくいかないようです。ここで何が間違っていますか?

4

2 に答える 2

3

キャストはプレーヤー コントローラーへのポインターを返すため、 -> を使用して逆参照する必要があります。

const MyCustomPlayerController* MyController = Cast<MyCustomPlayerController>(InController);
check(MyCustomPlayerController);  // asserts that the cast succeeded
const float MyVariable = MyCustomPlayerController->ControllerVariable;

`

于 2014-10-21T16:38:56.853 に答える