Okay to use "this" keyword in constructor/header?
So inside the constructor of some actor class I'd like to code something like this:
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):
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:
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).
Closing the question since this is something that needs to be changed in the editor (or allow us to suppress the warnings with metadata).
answered Aug 28 '18 at 08:41 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here