x

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"

Okay to use "this" keyword in constructor/header?

So inside the constructor of some actor class I'd like to code something like this:

 ATurret01::ATurret01()
 {
   TargetInfo = FTargetInfo(this, 1, true); // is this line okay?
 }

But is that proper? Of course I assume that initializing it in the header makes more sense but putting a this there feels even more awkward (it compiles and probably works):

 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Turret01|IDamageable")
 FTargetInfo TargetInfo = FTargetInfo(this, 1, true);

This will probably work just fine because TargetInfo is a struct but if TargetInfo were to be another actor or a class that references this class again then I would probably have to initialize it in the BeginPlay() instead.

I did find one issue with it so far however (but this is more related to having a reference to self). Anytime I delete a turret with that code in the editor I get this warning: alt text

Obviously the warning makes no sense for self-references but I guess that UE4 does not check for that prior to throwing such a warning. I suppose there is no metadata to prevent this warning.

As for the reason for me using a reference to self in the struct: It saves some performance later and I have to use structs instead of interfaces because UE4 does not work well with interfaces in certain cases (no support for UPROPERTY in my case and interfaces in TArrays don't seem very stable when sorting and such).

Product Version: UE 4.18
Tags:
selfref.png (20.2 kB)
more ▼

asked Nov 29 '17 at 07:08 AM in C++ Programming

avatar image

Napoleonite
595 87 102 151

avatar image Firefly74 Nov 29 '17 at 11:48 AM

That's odd ! I would think UE Check the case where there is a self ref.. using this in ctor isn't a problem.

i don't use the this in header, it feel so strange ( maybe it work fine )

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

1 answer: sort voted first

Closing the question since this is something that needs to be changed in the editor (or allow us to suppress the warnings with metadata).

more ▼

answered Aug 28 '18 at 08:41 AM

avatar image

Napoleonite
595 87 102 151

(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