C:\Program Files (x86)\Epic
Games\UE_4.17\Engine\Source\Runtime\Core\Public\UObject/WeakObjectPtrTemplates.h(55):
error C2338: TWeakObjectPtr can only
be constructed with UObject types
There is no any problem with the second variable “DamageCauser”.
I compared “WeakObjectPtrTemplates.h” in old and new version. It’s the same.
Please help with correct declaration. “ABaseCharacter” inherited from “ACharacter”.
I think the problem is that the compiler has not seen the definition of ABaseCharacter. You can tell by removing the ‘class’ (which is a habit best avoided anyway):
… and then you should get an error more like ‘unknown identifier: ABaseCharacter’. So you need to explicitly include the header containing ABaseCharacter at the top of this header:
#include "BaseCharacter.h"
This probably used to compile due to a different ordering of #includes.
I didn’t include some #includes to this header file.
It’s used in “BaseCharacter.h” also. I afraid to have a loop.
May be I tried already it. I’ll check.
I put away this issue and just commented all linked code.
And worked with other files.
This file had not be changed!!!
I turned back to this issue yesterday.
And miraculously this part of code started to work.
However, another issue appeared in the same file.
PawnInstigator(nullptrn);
It doesn’t work as it worked before. Do not compiled. Some problem with “nullptrn”.
Nevertheless next code works as usual
DamageCauser(nullptrn);
I changed the faulty part of code to
PawnInstigator();
and it was compiled.
But I didn’t check how does it work yet.
I don’t catch this thing. Definitely something is wrong.
Regarding my suggestion above, the static assert is inside the constructor, so it’s only important that the constructor has seen the full definition of ABaseCharacter. So to avoid circular includes, it would be better like this:
// MyClass.h
#pragma once
#include "MyClass.generated.h"
class ABaseCharacter; // Forward declare this
UCLASS()
class UMyClass : public UObject
{
GENERATED_BODY()
UMyClass(); // Explicitly declare a constructor
UPROPERTY()
TWeakObjectPtr<ABaseCharacter> PawnInstigator;
};
// MyClass.cpp
#include "MyClass.h"
#include "BaseCharacter.h" // Make sure we have the full definition of ABaseCharacter
UMyClass::UMyClass()
{
} // PawnInstigator will be constructed here, where the full definition of ABaseCharacter is known