我目前正在虚幻引擎4中开发我的第一个类。由于广泛使用UScript,我对纯C++中的类型转换工作方式感到有点困惑。更具体地说,类/对象类型转换。
我目前正在用MyCustomGameMode编写一个switch语句,它为MyCustomPlayerControllerVariable调用MyCustomPlayerController。
我要覆盖的有问题的函数是这样的:virtual UClass* GetDefaultPawnClassForController(AController* InController);
目前我正在尝试使用下面这行代码调用该变量,我知道这是不正确的,但我不确定为什么:
Cast<MyCustomPlayerController>(InController).MyCustomPlayerControllerVariable我对将"InController“转换为MyCustomPlayerController很感兴趣,但是Cast<MyCustomPlayerController>(InController)似乎不起作用,我在这里做错了什么?
发布于 2014-10-22 00:38:57
强制转换将返回一个指向播放器控制器的指针,因此您需要使用->来取消对它的引用。
const MyCustomPlayerController* MyController = Cast<MyCustomPlayerController>(InController);
check(MyCustomPlayerController); // asserts that the cast succeeded
const float MyVariable = MyCustomPlayerController->ControllerVariable;`
发布于 2015-06-26 09:32:41
当你强制转换时,它总是返回一个指针。因此,在从指针访问变量之前,请确保检查强制转换是否成功。
auto MyPC = Cast<MyCustomPlayerController>(InController);
if(MyPC)
{
MyPC->MyVariable;
}https://stackoverflow.com/questions/24500970
复制相似问题