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"

Weird Result from Attach Component to socket


I want to be able to attach the projectile that I've fired into any enemy actor that is hit

I'm using first person c++ sample code to achieve this

This is the code that I used

 void AEnemy::ReceiveHit(class UPrimitiveComponent* MyComp, class AActor* other, class UPrimitiveComponent* OtherComp, bool bSelfMoved, FVector HitLocation, FVector HitNormal, FVector NormalImpulse, const FHitResult& Hit)
     USkeletalMeshSocket* socket = Cast<USkeletalMeshSocket>(USkeletalMeshSocket::StaticClass()->GetDefaultObject());
     socket->InitializeSocketFromLocation(Mesh, HitLocation, HitNormal);
     other->AttachRootComponentTo(Mesh, socket->BoneName, EAttachLocation::KeepWorldPosition);

     AProjectile* projectile = Cast<AFirstSprintProjectile>(other);

Problem is I get weird result that the projectile is attached on the air, on the part where the capsule component is collide with the projectile.

What I need is the projectile's attached in the mesh

Where do I went wrong? Do I need to change the collision component shape?alt text see pictures for references


EDIT I use UnregisterComponent on ProjectileMovement component to stop the projectile from moving, and set the collision to NoCollision, since the projectile could still be moved and hit the enemy themselves if it's not set to NoCollision

Product Version: Not Selected
capture.png (731.3 kB)
more ▼

asked Nov 04 '14 at 09:52 AM in C++ Programming

avatar image

48 10 13 14

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

1 answer: sort voted first

You don't need to initialize a socket for that. I've disabled the collisions of projectiles on the capsule collider and set the character mesh to block them. After that just attach the component like this:

 other->AttachRootComponentTo(Mesh, Hit.BoneName, EAttachLocation::KeepWorldPosition);
more ▼

answered Nov 04 '14 at 10:20 AM

avatar image

6k 163 130 305

avatar image ernesernesto Nov 04 '14 at 11:35 AM

Hi xlar8or!

Unfortunately, the Hit.BoneName always have an empty result, that's why I'm initializing a socket, anyway I'm using SnapToTarget to achieve my goal. It works for smaller enemy, but when facing a big enemy like picture above, the projectile also scaled into target size, which is kind of expected behavior from snapping but not like the result I'm hoping for

avatar image xlar8or Nov 04 '14 at 02:35 PM

Hit.BoneName is empty because you are using the Capsule Collider to detect the hit, and that doesn't have bones. You have to disable the collision with projectiles on the Capsule Collider and set it up on the Skeletal Mesh so it can fill the Hit.BoneName with the closest bone.

avatar image ernesernesto Nov 05 '14 at 03:00 AM

alt text ! Here are my collision settings for capsule collider and the skeletal mesh, when I set it like this, the character falls through the world.

Tried setting all into block but ignore the projectile on the capsule collider, but it still collides with the capsule collider alt text

avatar image xlar8or Nov 05 '14 at 10:32 AM

As you can see the capsule collider is blocking projectiles. Set the profile to Pawn and change it again to Custom and just change the projectile channel to ignore. Then make sure the mesh is blocking projectiles and the projectile blocks pawns and you should be good :)

avatar image ernesernesto Nov 07 '14 at 08:43 AM

I set the correct collision and works gracefully now, thanks for your time!

avatar image xlar8or Nov 07 '14 at 10:32 AM

You're welcome :)

(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