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. 

How can I attach a blueprint weapon to socket?

I have C++ class of my character and also I have a blueprint generated class of weapon. How can I attach the weapon? I still can't figure out, how can I create components of blueprint generated classes.

Thank you.

Product Version: Not Selected
Tags:
more ▼

asked Aug 09 '14 at 11:10 PM in C++ Programming

avatar image

Ized
26 2 5 8

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

2 answers: sort voted first

I recommad you to create (atleast dummy) base class for weapon with functions and varables that your weapon needs, it will be easier for you to operate blueprint made weapons based of that class in C++ this way.

In that weapon base class, you could have varable:

 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Weapon)
 UStaticMesh WeaponMesh;

And in defaults of weapon based class you will see mesh selector, you set mesh of a weapon, whih later you can read and apply to component in character

more ▼

answered Aug 10 '14 at 12:20 AM

avatar image

Shadowriver
36.6k 931 169 1111

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

Here is how I attach my weapon to the FPS Mesh in my project. I created a socket on the bone of the mesh and then spawn the Weapon Actor and then attach it. Like this. (See Link here for better view.)

 bool AMyProjectWeapon::AttachWeaponToPawn(APawn* WeaponOwner, FString SkeletalCompName)
 {
     OwningPawn = WeaponOwner; // Sets the owner of this weapon. (Note: OwningPawn  is a APawn* member in my weapon class.)
     SetOwner(OwningPawn); // AActor::SetOwner(APawn*);
 
        // A method i created to get any skeletal component from the owning pawn. (Could be made a template to function to get any type.)
     USkeletalMeshComponent* ArmMesh = GetPawnSkeletalComp(SkeletalCompName); 
 
     if (ArmMesh) // Check to see if our rig Skeletal Mesh Component is good.
     {
                 // AActor::AttachRootComponentTo(..)
         AttachRootComponentTo(ArmMesh, FName(TEXT("WeaponPoint")), EAttachLocation::SnapToTarget); // Attach the root component of our Weapon actor to the ArmMesh at the location of the socket.
         return true; // Note: We can only assume it is attached, since epic did not provide a return value.
     }
     else
     {
         return false;
     }
 }
 
 USkeletalMeshComponent* AMyProjectWeapon::GetPawnSkeletalComp(FString ComponentName)
 {
     TArray<UActorComponent*> Components; // Array for Pawns components
     USkeletalMeshComponent* ArmMesh = NULL; // Will hold the skeletal mesh we want
 
     if (OwningPawn)
         OwningPawn->GetComponents(Components); // Get the components from the owning pawn
 
     for (UActorComponent* Comp : Components)
     {
         ArmMesh = Cast<USkeletalMeshComponent>(Comp); // Cast any component to Skeletal Comp.
         if (ArmMesh) // If we have a skeletal mesh
         {
             if (ArmMesh->GetName() == ComponentName) // Check to see if its the one we want.
                 return ArmMesh;
         }
     }
 
     return NULL; // Finished with out finding the component we wanted.
 }

Hope it helps. WCode

more ▼

answered Aug 10 '14 at 05:18 AM

avatar image

WCode
508 43 44 73

(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