Hello
I’m having an issue with TWeakObjectPtr.
I’m declaring my damage structure as something like:
USTRUCT()
struct FTakeHitInfo
{
GENERATED_USTRUCT_BODY()
UPROPERTY()
TWeakObjectPtr<class AMyCharacter> PawnInstigator;
UPROPERTY()
TWeakObjectPtr<class AActor> DamageCauser;
UPROPERTY()
uint8 DamageEventClassID;
// etc.
};
The issue arise in the lines:
UPROPERTY()
TWeakObjectPtr<class AMyCharacter> PawnInstigator;
It doesn’t compile, with the error:
1>e:\unrealengine\epic games\4.7\engine\source\runtime\core\public\uobject\WeakObjectPtrTemplates.h(43): error C2338: TWeakObjectPtr can only be constructed with UObject types
1> e:\unrealengine\epic games\4.7\engine\source\runtime\core\public\uobject\WeakObjectPtrTemplates.h(38) : while compiling class template member function 'TWeakObjectPtr<AMyCharacter,FWeakObjectPtr,FIndexToObject>::TWeakObjectPtr(const T *)'
1> with
1>
1> T=AMyCharacter
1> ]
1> E:\Zoc_My_Workspace\MyGame\Source\My\Public\MyTypes.h(128) : see reference to function template instantiation 'TWeakObjectPtr<AMyCharacter,FWeakObjectPtr,FIndexToObject>::TWeakObjectPtr(const T *)' being compiled
1> with
1>
1> T=AMyCharacter
1> ]
1> E:\Zoc_My_Workspace\MyGame\Source\My\Public\MyTypes.h(94) : see reference to class template instantiation 'TWeakObjectPtr<AMyCharacter,FWeakObjectPtr,FIndexToObject>' being compiled
1>e:\unrealengine\epic games\4.7\engine\source\runtime\core\public\uobject\WeakObjectPtrTemplates.h(43): error C2338: TWeakObjectPtr can only be constructed with UObject types
1> e:\unrealengine\epic games\4.7\engine\source\runtime\core\public\uobject\WeakObjectPtrTemplates.h(38) : while compiling class template member function 'TWeakObjectPtr<AMyCharacter,FWeakObjectPtr,FIndexToObject>::TWeakObjectPtr(const T *)'
1> with
1>
1> T=AMyCharacter
1> ]
1> e:\zoc_My_Workspace\MyGame\source\My\public\MyTypes.h(128) : see reference to function template instantiation 'TWeakObjectPtr<AMyCharacter,FWeakObjectPtr,FIndexToObject>::TWeakObjectPtr(const T *)' being compiled
1> with
1>
1> T=AMyCharacter
1> ]
1> e:\zoc_My_Workspace\MyGame\source\My\public\MyTypes.h(94) : see reference to class template instantiation 'TWeakObjectPtr<AMyCharacter,FWeakObjectPtr,FIndexToObject>' being compiled
So, it says I can’t use TWeakObjectPtr with non-UObject classes.
My character declaration (in MyCharacter.h file) is:
UCLASS(config=Game)
class AHavenCharacter : public ACharacter
{
//etc.
};
But, if in the original FTakeHitInfo declaration I change to:
UPROPERTY()
TWeakObjectPtr<class ACharacter> PawnInstigator;
it works!
I don’t really understand why (unless something is declared on MyTypes.generated.h). Also, I’m hesitant to use the ACharacter Class, to avoid casting it to AMyCharacter every time I want to check something.
Also, I can’t include MyCharacter.h on my FTakeHitInfo declaration header, since it would cause a circular includes issue.
Ideas on how to solve this? Should I just use the base ACharacter class and cast it to AMyCharacter every time I want to check something or is there a better way of doing this?