'AttachTo' Deprecated

After getting a Warning about the AttachTo method getting deprecated, I decided to change the code now as I’m already on 4.17.2 and the video is for version 4.12.5.

The new method (AttachToComponent (link here)) doesn’t really accept just one parameter. The 2nd parameter accepts a FAttachmentTransformRules. Right now, with my current understanding of things, I’m going with FAttachmentTransformRules::KeepRelativeTransform.

If someone can explain a bit more that would be helpful.
Thank You.

1 Like

I tried something similar, using a different value of FAttachmentTransformRules, and got a recommendation to use the USceneComponent::SetupAttachment method instead. So the relevant part reads like this:

LaunchBlast = CreateDefaultSubobject<UParticleSystemComponent>(FName("Launch Blast"));
LaunchBlast->SetupAttachment(CollisionMesh);

From the docs, regarding this method:

Generally intended to be called from its Owning Actor’s constructor and should be preferred over AttachToComponent when a component is not registered.

5 Likes

I was using AttachToComponent until I found this. Nice find!

1 Like

AttachToComponent crashed UE for some reason, and this worked like a charm, thank you so much!!

1 Like

Privacy & Terms