Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

TWeakObjectPtr doesn't work in 4.17 as before

Some code have worked without any issues in 4.16 version.

 TWeakObjectPtr<class ABaseCharacter> PawnInstigator;
 TWeakObjectPtr<class AActor> DamageCauser;

First part doesn't work in 4.17 version

 TWeakObjectPtr<class ABaseCharacter> PawnInstigator;

With next notice

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".

Product Version: UE 4.17
more ▼

asked Aug 19 '17 at 06:03 PM in C++ Programming

avatar image

49 10 13 22

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first


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):

 TWeakObjectPtr<ABaseCharacter> PawnInstigator;

... 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.

Hope this helps,


more ▼

answered Aug 22 '17 at 03:10 PM

avatar image

Steve Robb STAFF
2.8k 58 31 102

avatar image SvarogZ Aug 23 '17 at 04:50 AM

Dear Steve,

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.


It doesn't work as it worked before. Do not compiled. Some problem with "nullptrn".

Nevertheless next code works as usual


I changed the faulty part of code to


and it was compiled. But I didn't check how does it work yet.

I don't catch this thing. Definitely something is wrong.

I'll test your solution anyway.

Thank you.

avatar image Steve Robb STAFF Aug 23 '17 at 10:46 AM

Do you mean nullptr, rather than nullptrn?

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

 class UMyClass : public UObject

     UMyClass(); // Explicitly declare a constructor

     TWeakObjectPtr<ABaseCharacter> PawnInstigator;

 // MyClass.cpp
 #include "MyClass.h"
 #include "BaseCharacter.h" // Make sure we have the full definition of ABaseCharacter

 } // PawnInstigator will be constructed here, where the full definition of ABaseCharacter is known


avatar image SvarogZ Aug 24 '17 at 08:35 PM

Thank you!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question