x

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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Attach to Actor does not render the attached actor

Hello,

I'm currently using the ShooterGame project to implement a sticky bomb that would basically stick onto any character that it comes in contact with. I've managed to attach the bomb to a character as seen in the image below, but the bomb would not get rendered as soon as it get attached to the character.

alt text

This is the code snippet for attaching to the character.

 SetActorLocation(HitResult.ImpactPoint);
 
 const FAttachmentTransformRules AttachmentRules(EAttachmentRule::KeepRelative, true);
 
 //AttachToComponent(OtherComponent, AttachmentRules, TraceResult.BoneName);
 AttachToActor(OtherActor, AttachmentRules, TraceResult.BoneName);

I've confirmed that OtherComponent, OtherActor and the TraceResult.BoneName are valid data and not empty / null. I've considered the situation where the bomb would be hidden underneath the character's mesh since the bomb is not that big, so I've modified the SetActorLocation(...) code above to:

 TArray<UStaticMeshComponent*> StaticMeshes;
 GetComponents<UStaticMeshComponent>(StaticMeshes);
 
 for (const UStaticMeshComponent* Component : StaticMeshes)
 {
     if (Component->GetName() == m_GrenadeMeshName)
     {
         m_GrenadeMeshBound = Component->Bounds.BoxExtent;
         break;
     }
 }
 ....
 const FVector NewPosition = TraceResult.ImpactPoint - GetActorForwardVector() * (m_GrenadeMeshBound);
 SetActorLocation(NewPosition);

So basically I've gotten the extent of the grenade mesh in order to pull the grenade back out by the extent of the grenade, hoping that it will stick out from the character's mesh but that didnt seem to solve anything.

I was wondering if anyone's seen this behavior or can point out what I'm doing wrong with this. Thank you in advance!

Product Version: UE 4.16
Tags:
capture.png (21.3 kB)
more ▼

asked Nov 11 '18 at 04:41 PM in C++ Programming

avatar image

Kaltz
1 4 6

avatar image DarkwindRichard Nov 13 '18 at 07:17 PM

Hi Kaltz,

I created a new project in 4.16 with the FPS Template to try to recreate this. I noticed that after I attached the projectile to the actor, the projectile kept moving because it kept simulating physics. That plus having to maintain a relative location to the target actor made the projectile jump in position then continue simulation. Have you tried setting the attachment rules to be "snap to target," setting velocity to zero, stop simulating physics for the grenade, etc.?

avatar image Kaltz Nov 14 '18 at 06:08 AM

Hey DarkWindRichard,

Thanks for getting back to me. I've thought about that and had already added the following code after attaching the projectile:

 SetActorEnableCollision(false);
 m_MovementComponent->StopMovementImmediately();
 m_CollisionComponent->SetSimulatePhysics(false);

But that didnt change anything, but changing the attachment rule to SnapToTarget instead of KeepRelative as you suggested fixed the issue! I'm able to see the projectile stuck to the pawn.

But I'm seeing a new issue where the projectile is attached to the same location no matter where I shoot it from, as well as where it hits the pawn. I've checked the impact, point position, forward vector etc and checked that they werent all the same value.

I've tried changing EAttachmentRule::SnapToTarget to EAttachmentRule::KeepWorld and that seems to fix the issue of the projectiles not attaching to the "correct" position on the pawn. I was wondering if its okay to use KeepWorld as it seems to do what I want according to the comment on the enum and what I'm seeing is happening.

avatar image DarkwindRichard Nov 14 '18 at 04:12 PM

Hi Kaltz,

Yep! Using KeepWorld should be what you are looking for. That will keep the projectile's world transform once the attachment has occurred, and then since it is attached to the actor at that point it will maintain that relative position to the actor.

avatar image Kaltz Nov 15 '18 at 02:19 PM

Sweet, thank you very much for the help DarkwindRichard! I really appreciate it!

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

1 answer: sort voted first

For anyone who stumbles across this post, the issue I was having was not the FAttachmentTransformRules I was passing into the AttachToActor / AttachToComponent function. I've initialized the enums to EAttachmentRule::KeepRelative but instead, initializing it to EAttachmentRule::KeepWorld solved the issue for me.

more ▼

answered Nov 15 '18 at 02:18 PM

avatar image

Kaltz
1 4 6

(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