Odd bug (?) with Blueprint compiler, Child Actor Component & Construction Script

Hello,

A couple of days ago we have faced a very strange bug (?) with some of our blueprints. After a bit of digging into the issue I was able to create a projects with minimal reproducible form of this issue (please find it attached). I prepare actually two versions: for UE4.18 and for UE 4.16. The issue the same but with a bit differences in details.

UE version (main): 4.18.0-3709383+++UE4+Release-4.18

UE version (as an additional information about the issue): 4.16.3-3561208+++UE4+Release-4.16

Short issue description:

References to Child Actor Component’s actor stored in Construction Script become invalid under some circumstances.

Due to the nature of the issue, this short description could be misleading and hard to understand, so please find more details below.

Attempt to describe the issue in more details:

  1. You have Blueprint actor class “A”
  2. You have Blueprint actor class “B” which a child of “A”
  3. You have Blueprint actor class “C”
  4. Class “A” have ChildActorComponent “CAComponent” with Child Actor Class set to “C”
  5. Class “A” have variable “V”, which type is Actor reference
  6. Class “A” have Construction Script which get child actor from component “CAComponent” and store reference to it (cache it) into the variable “V” of “A”
  7. Class “A” get value of “V” in multiple places of its Event Graph (so as “B” which a child of “A”). Event Graph of “A” (so as Event Graph of “B”) never Set value of “V”.
  8. [The problem] While in Construction Script of “A”, “V” is always properly initialized with valid values and points to valid Actor objects, the value of “V” in event graph of “A” sometimes (rarely and under very odd circumstances, see below) become “None” in run-time.
  9. Most of the time all work just fine, the odd circumstances mentioned above is … compiling of Blueprint “A” (!?). Please see “Steps to reproduce” below for more details about issue manifestation conditions.

Steps to reproduce:

  1. Please use attached project(s) to reproduce. The differences between 4.18 and 4.16 will be notices below.
  2. Open attached project
  3. Run project in Simulate mode. Observe the message “BEGIN PLAY: Child actor ref is VALID”. This mean all work as expected (value of “V” is valid in Event Graph of “A” - see issue description above")
  4. You may repeat previous action multiple time and will always observe normal message “… ref is VALID”
  5. Now open Blueprint A and just click “Compile” to recompile it without any changes. (ignore messages, they are from Construction Script and always notify that all is Ok).
  6. Run project again in Simulate mode.This time you will observe error message (in red) “BEGIN PLAY: Child actor ref is INVALID”. That the problem: now “V” is not valid in Event Graph of “A” while no changes were made in Level or in blueprints.
  7. You may repeat previous action multiple time and now will always observe error message “… ref is INVALID”
  8. (UE 4.16 specific) Recompile the “A” once again.
  9. (UE 4.16 specific) Run project again in Simulate mode. Now you will observe normal message “BEGIN PLAY: Child actor ref is VALID” and all work as expected, with no issues. From now and further, recompilation of “A” will not broke the run-time logic (this is specific only for UE 4.16; for UE 4.18, consecutive recompilation doesn’t affect project any more).
  10. Reopening project render it to working state again for both versions of UE (you may save changes in Level after compilation or discard it - no differences).

Thereby, just compiling blueprint without any modification in project (level or blueprint itself) lead to odd side-effects (initially you got broken project, then it magically fixed by the same action that broke it previously).

Additional notes: Initially we notice the issue with UE 4.18, after we switching our project from 4.16 to 4.18. We never have seen it before with UE 4.16 (use it from first day of 4.16 release). But after digging into the issue we discover that issue actually manifest itself in UE 4.16 too, but with a bit difference (see above). This is why I provide here test projects for both versions.

Hello DVRQProgrammer,

I was able to reproduce this issue on our end. I have written up a report and I have submitted to the developers for further consideration. I have provided a link to the public tracker below. Please feel free to use the link provided for future updates.

Link: Unreal Engine Issues and Bug Tracker (UE-52046)

Make it a great day