Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Error for FAttachmentTransformRules

I'm trying to attach one character to another, for that I'm trying to use AttachToActor(). This is my implementation: On the header:

 FAttachmentTransformRules AttachRules;

On the .cpp file:

 Survivor->AttachToActor(this, AttachRules);

Survivor is a variable that points to the other Character. But when I hit compile I get this error:

error C2512: 'FAttachmentTransformRules': no appropriate default constructor available

Anyone can point me on the right direction?

Product Version: UE 4.19
more ▼

asked Jul 18 '18 at 04:00 PM in C++ Programming

avatar image

29 7 12 15

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

The struct "FAttachmentTransformRules" does not have a default constructor, as the error is telling you, so you would be required to initialize it in your class's constructor or, in the header file, you could give it a default value ("FAttachmentTransformRules AttachRules = ...;"). The available defaults are listed in the "Constants" section of the documentation page.

more ▼

answered Jul 18 '18 at 04:23 PM

DarkwindRichard (suspended)
avatar image RainbowCookie32 Jul 18 '18 at 05:06 PM

I see. How I should set it up on the class constructor? Sorry, I'm still learning. Can you provide me an example of the struct initialization?

avatar image DarkwindRichard Jul 18 '18 at 07:03 PM

Sure! What I'm talking about, so you know for the future, is called the "member initializer list". If you look at the "Constructors" section in the documentation, there are two constructors you can use. The only difference between the two is the one with two parameters uses the same rule for location, rotation, and scale attachment rules. If you were going to use the first, your constructor would look something like this:

     : AttachRules(EAttachmentRule::KeepRelative, true)
     // Rest of your constructor...

If you used the other contructor, then you would just supply two more EAttachmentRule arguments.

avatar image RainbowCookie32 Jul 18 '18 at 08:13 PM

My contructor look like this now

  // Sets default values
     AKillerBase::AKillerBase() : AttachRules(EAttachmentRule::KeepRelative, true)
          // Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
         PrimaryActorTick.bCanEverTick = true;

But I'm still getting the same error. Did I do something wrong?

'FAttachmentTransformRules': no appropriate default constructor available

avatar image DarkwindRichard Jul 19 '18 at 02:42 PM

Hmm, that seems like it should be fine... Does the compile error provide you with a specific line of code? If so, what does it look like?

avatar image RainbowCookie32 Jul 19 '18 at 03:50 PM

I actually noticed that the error is no longer on the .cpp file, but rather the .gen.cpp

KillerBase.gen.cpp(297) : error C2512: 'FAttachmentTransformRules': no appropriate default constructor available

And this is line 297 on that file:

avatar image DarkwindRichard Jul 19 '18 at 04:11 PM

Looking into it more, "FAttachmentTransformRules" is not marked as a Blueprint type so I don't believe it would show up in the details panel at all.

If you need to be able to edit the attach rules in editor, what you can do instead is expose three "EAttachmentRule" properties (one for each of position, rotation, and scale), or one property if all three rules would be the same, as well as a bool property for whether or not to weld simulated bodies together when attaching. You could then create the "FAttachmentTransformRules" object as a local variable when you set the attachment.

If you don't need it to show up in the editor because the attachment will always be the same, then it does not need to be a class-level variable and can be created locally.

avatar image RainbowCookie32 Jul 19 '18 at 04:31 PM

I don't need it on Blueprints so I can try to declare it locally. So I'd go like this?

 void AKillerBase::KillerInteraction()
     if (Survivor && bSurvivorInRange)
         FAttachmentTransformRules AttachRules;
         Survivor->AttachToActor(this, AttachRules);

Because like this I'm already getting the default constructor thing on VS and the engine. Thanks for the help btw

avatar image DarkwindRichard Jul 19 '18 at 05:19 PM

Kind of, yeah. However, like the error is telling you, doing it that way is still utilizing the default constructor (which doesn't exist for that type). You could either supply the values yourself, like with the member initializer list, or you could use one of the constants like this:

 Survivor->AttachToActor(this, FAttachmentTransformRules::KeepWorldTransform);
avatar image RainbowCookie32 Jul 19 '18 at 06:17 PM

Finally it compiles. Thank you

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question