Error C2039: 'AttachTo' : is not a member of 'UStaticMeshComponent'

Hi guys,

I been stuck on this for several days now, and I get that error for anything that uses AttachTo:

 collisionComp = CreateDefaultSubobject<USphereComponent>(TEXT("CollisonComp"));
  RootComponent = collisionComp;
 
  spellMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("SpellMesh"));
  spellMesh->AttachTo(RootComponent);

  projectileMovementComp = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovementComp"));

  projectileMovementComp->AttachTo(RootComponent);

I included Engine.h and even checked if attachto actually exsists for ustatic,uskeletal and projectilemovement and it does not seem to exist.

Mind you I never had this issue in 4.6.

Thank you,

Did you mean to use UStaticMeshComponent instead?

If you want to attach components:
In the constructor use AttachParent

SpringArm = ObjectInitializer.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("SprintArm"));
SpringArm->AttachParent = CapsuleComponent;

Camera = ObjectInitializer.CreateDefaultSubobject<UCameraComponent>(this, TEXT("Camera"));
Camera->AttachParent = SpringArm;

Otherwise use AttachTo

If you want to attach actors to an another actor use:

AttachRootComponentToActor

or

AttachRootComponentTo

Also i think youā€™re creating the actor instances in the wrong way. Try spawning your actors with the SpawnActor call

UWorld* const World = GetWorld();
if (World)
{
   World->SpawnActor<AActor>(AActor::StaticClass());
}

I hope it helps!
Cheers! :slight_smile:

I fixed the typo, but the error still persist for both.

Iā€™m not trying to spawn something in the world, Iā€™m simply setting up the class for easy blueprint editing. I tried both and neither worked =/

Iā€™m using 4.7.3 btw, you seem to be using something older.

So after a bit of looking around I finally fixed the issue, for some reason AttachTo still doesnā€™t exist, and AttachToRoot simply crashed the editor.

spellMesh->AttachParent = RootComponent;

Using AttachParent=root worked for me. Thanks for the help guys.

EDIT: AttachParent does not work after I rebuilt it a 2nd time. It now gives me the same error as the title.

1 Like

I had that issue beforeā€¦but canā€™t remember why it was happeningā€¦ are you including the correct headers?

That is the same code i postedā€¦

The code is compatible with 4.7.3 as well so it is not the case.

what headers should i be including? i rebuilt this and now AttachParent is giving me the same stupid error: error C2039: ā€˜AttachParentā€™ : is not a member of ā€˜UProjectileMovementComponentā€™

I restarted vs2013 and included that header, it fixed the issue for my mesh but not projectile component.

Edit: Iā€™m trying AttachToRoot() for it, I have engine.h included in my main project file.

in your CPP file you should have

#include "GameFramework/ProjectileMovementComponent.h"

for your projectile

Also do you have

#include ā€œEngine.hā€

in your main project header? Not sure if that would help but it adds extra stuff

you should use ā€œSetupAttachment()ā€ instead of ā€œAttachTo()ā€.

it works for me without any other changes (UE5).

1 Like

This worked for me. Thank you!

1 Like