I am trying to add a BoxComponent as the actor root and attach a DecalComponent as the child. Unfortunately, my project crashed when I open it, claiming that the “SetupAttachment” line is causing an Exception Access Violation. Here are my declarations: UPROPERTY(BlueprintReadWrite) UBoxComponent* TrackCollider; UPROPERTY(BlueprintReadWrite) UDecalComponent* TrackDecal
And here is a snippet from my CPP file:
`TrackCollider->SetupAttachment(RootComponent);
I suggest finding the code of a working component to check how it looks, you may not have all the stuff included and maybe some of the variables are not declared correctly like pointers and the like.
Do you first create and set up the TrackCollider object?
If you put a breakpoint into your project on the SetupAttachment line, and check TrackDecail and TrackCollider, are they both valid objects in the Watch inspector window?
Sometimes, a C++ class may end up causing a blueprint subclass to be invalid. If this is the situation for you, see if you can “revert” all properties on the blueprint (if you can temporarily comment out the line that crashes) and re-save it. And if you can’t get it to load again, re-create the blueprint subclass from the C++ base class, and see if it behaves better.
The reason for this is that adding or updating new properties may sometimes be incompatible with the data stored in the blueprint (used to initialize the native objects,) and in such a case, I have seen initialization fail (although details may vary.)
Believe it or not, my compiler was just displaying the error on the wrong line. The problem was that I didn’t assign a BoxComponent with CreateDefaultSubObject.