UE4: Reference to Default Subobject Of

~ 2 minute read.

Blue­print ver­i­fi­ca­tion er­rors are in­ter­est­ing. Es­pe­cial­ly if while cook­ing or sav­ing the ed­i­tor spits out “BP[…] con­tains in­valid da­ta” which leaves you pret­ty clue­less.

You will find, though, that when de­bug­ging the ed­i­tor, it breaks some­where in Obj.cpp on an as­ser­tion in CheckDefaultSubobjectsInternal(). Note that you need to have de­bug sym­bols in­stalled.

There you’ll find a UE_LOG call to a log cat­e­go­ry that is off by de­fault. With

Log LogCheckSubobjects All

you can en­able it to see the er­ror mes­sages, some­thing along the lines of:

? has a ref­er­ence to de­fault sub­ob­ject (?) of ?.

What caus­es this er­ror? For me it was the fol­low­ing:

UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
UMyCustomObject* Object;

And then us­ing a ref­er­ence to Object in a “Se­lect” node in the child blue­print of my C++ class. Why is this a prob­lem? I marked the prop­er­ty as BlueprintReadOnly, but UE4 can­not con­trol that I on­ly read from a ref­er­ence. I might as well change the ref­er­enced ob­ject as much as I like and there­fore write to it.

I fixed this by us­ing BlueprintReadWrite in­stead, as I didn’t have a good rea­son for pre­vent­ing writes. You may want to cre­ate spe­cial get­ter in­stead or some­thing.

Writ­ten in 15 min­utes