I have an object that is programmed to interact with interfaces so we can test it. So far it has been fine, but when I tried to cast the game mode to the interface it freaked out.
return Cast<IFighterWorld>(GetWorld()->GetAuthGameMode());
I decided to try an intermediate step.
return Cast<IFighterWorld>(Cast<UObject>(GetWorld()->GetAuthGameMode()));
Thing is, it fails on the cast to UObject with the same error.
Here’s everything it spits out to stderr on it:
2>D:\programs\Epic Games\UE_4.17\Engine\Source\Runtime\CoreUObject\Public\Templates/Casts.h(193): error C2664: 'UObject *TCastImpl<From,To,ECastType::UObjectToUObject>::DoCast(UObject *)': cannot convert argument 1 from 'AGameModeBase *' to 'UObject *'
2> with
2> [
2> From=AGameModeBase,
2> To=UObject
2> ]
2> D:\programs\Epic Games\UE_4.17\Engine\Source\Runtime\CoreUObject\Public\Templates/Casts.h(193): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2> D:\home\xxxx\documents\Unreal Projects\BeatBoxers\Source\BeatBoxers\FighterCharacter.cpp(51): note: see reference to function template instantiation 'To *Cast<UObject,AGameModeBase>(From *)' being compiled
2> with
2> [
2> To=UObject,
2> From=AGameModeBase
2> ]
So now I am confused.
It says it can’t cast an AGameModeBase into an UObject, but it is derived from UObject.
What is going on here?
I am thinking of just setting it to
return Cast<IFighterWorld>((UObject *)(GetWorld()->GetAuthGameMode()));
If I do that it proceeds past that point in the compilation and then fails on some of the unresolved external references to interface functions I have yet to implement, so I think it works, but it feels dirty.
Can anyone explain to me why I am unable to cast an AGameModeBase * to an UObject *?