Calling AttachTo() In Constructor now causes Crash

Just ported our project over to 4.12 to give Vulkan on Mobile a quick go, and hit a crash during the project loading up, caused by this offending block of text:

I understand why the crash occurs, since SatelliteMesh doesn’t have an actual StaticMesh at this point and therefore it can’t find the socket / mesh to attach to. In previous engine versions you’d get a log warning for this - but once gameplay started it didn’t matter since it was constructed from the template blueprint with a mesh specified, and all worked well.

Now however, I’m not sure where to call this. I’ve put it into PostInitializeComponents() for the time being - but that crashes when I open up a new blueprint, since again there’s no mesh there. The only other place would be BeginPlay() - but I don’t think that’s such a great idea is it? There’d be lots of time during initialization where the component is not where I want it to be :confused:

Ahhh so, it appears AttachTo has been deprecated and using AttachToComponent with the new arguments means that this works just fine.

Would it be possible to make ‘AttachTo’ not deprecated but completely void and stop compilation? Otherwise these crashes will be hard to trace.

Hey -

I tried adding a new class and using AttachTo() however I did not receive a crash when I restarted the project.

The code used was as follows:

Box = CreateDefaultSubobject<UBoxComponent>(TEXT("Box"));
Box->AttachTo(RootComponent);

Sphere = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere"));
Sphere->AttachTo(Box);

After compiling the class I was able to close / reopen the project without a crash. Can you attach the log file and callstack from the crash that you’re receiving for additional information? Also, can you point out where AttachtTo has been deprecated? I was not able to find mention of this in the source code.

Hey , I’m using 4.12 Preview 1 from the Launcher and it’s telling me to stop using AttachTo(); and use AttachToComponent(); instead with the new arguments.

I’m actually not sure how it even compiled with the deprecation warnings… something weird must have happened…

The deprecation warnings are meant to inform you that the function does still work in the current version but will no longer work in future versions. This is intended to give you the chance to make the necessary changes without simply no longer working. If you can provide the callstack and log files from the crash you mentioned I can continue investigating. However, as the warning mentions, it would be best to switch to using the new function call instead as soon as possible.

I just noticed your example you posted above, out of interest what happens for you when you try to attach it to a Skeletal mesh with a socket?

I think that was what caused the crash for me.

I tried using a SkeletalMeshComponent and a ParticleSystemComponent as shown in your original screenshot:

SkeleMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("SkeleMehs"));

RootComponent = SkeleMesh;

Party = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("Party"));
Party->AttachTo(SkeleMesh, TEXT("pelvis"), EAttachLocation::SnapToTarget);

I was able to compile and create a blueprint of the class which shows both the skeletal mesh and the particle system components and allows me to set both and add an instance of the blueprint to the level. As mentioned, if you are getting a warning to use AttachToComponent() instead then it would be best to go ahead and do so. If you are still getting a crash, can you please include your callstack and log files.

Hey , I’ll get back to you on this after a little more investigating!

Hey -

Have you have a chance to investigate the crash you were receiving? If you are still getting a crash, please include the callstack and log files from the crash as well as your machine ID.

As mentioned, if the deprecated warning mentions to use AttachToComponent(), I would do that instead. Let us know if you have any related to the new function as well.

Cheers

Have you tried using SetupAttachment() rather than AttachToComponent?

This. SetupAttachment is the new AttachTo() when used in a constructor.

Hello, I’m new to Unreal Engine, and following the “Blueprint 3rd Person Game” tutorial. On Step 21, setting up the sphere collision construction script, the narrator says to not use the AttachToComponent. The inputs in the video look different for his AttachTo… I searched for “SetupAttachment” but got no results.

Whats the current method in UE 4.15 for attaching the collision component to mesh?

Note: So far I’ve only used the graphical editors and have not dug into the code.

If this is the case, shouldn’t the message include this instead of AttachToComponent? I believe Epic really needs to have a place for all the deprecations and examples of what/how to change them, so people like me and others just get a message and no more explanation or needed data to figure this out.