Announcement

Collapse
No announcement yet.

Equip - UnEquip Items(Weapons-Bags-Etc..)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Equip - UnEquip Items(Weapons-Bags-Etc..)

    i'm new programmer who want to learn unreal engine ..
    i watched many tutoriols about create characters,actors,weapons,etc
    all with Blueprints,, but when i made C++ Project i had some problems..
    That's my first question, and it is :
    How to Equip and UnEquip things ?
    First, i made actor called WeaponActor
    WeaponActor.cpp:
    Code:
    AWeaponActor::AWeaponActor()
    {
        WeaponMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("WeaponMesh"));
        RootComponent = WeaponMesh;
        WeaponMesh->AttachTo(RootComponent);
    }
    Now Add to character weapon blueprint:
    Code:
    ATheWalkingDeadCharacter::ATheWalkingDeadCharacter()
    {
        static ConstructorHelpers::FObjectFinder<UBlueprint> RifleBlueprint(TEXT("/Game/Blueprints/Weapons/SK_AR4"));
        RifleSpawn = NULL;
    
        if (RifleBlueprint.Succeeded())
        {
            RifleSpawn = (UClass*)RifleBlueprint.Object->GeneratedClass;
        }
    }
    Now press button for Equip/Unequip Weapon:
    Code:
    void ATheWalkingDeadCharacter::EquipRifle()
    {
        FActorSpawnParameters SpawnParams;
        SpawnParams.Owner = this;
        SpawnParams.Instigator = Instigator;
        AWeaponActor* RifleSpawner = GetWorld()->SpawnActor<AWeaponActor>(RifleSpawn, SpawnParams);
        AWeaponActor* PistolSpawner = GetWorld()->SpawnActor<AWeaponActor>(PistolSpawn, SpawnParams);
        if (bRifleEquipped)
        {
            bRifleEquipped = false;
            if (RifleSpawner)
            {
                RifleSpawner->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetIncludingScale, FName("RifleLeftSocket"));
            }
        }
        else
        {
            bRifleEquipped = true;
            if (RifleSpawner)
            {
                RifleSpawner->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetIncludingScale, FName("RightHandRifleWeaponSocket"));
            }
        }
    }
    And when i equip item, it works !
    But when i have to Unequip it, i have this problem :

    Bug when equip\unequip weapon
    that he spawn many actors, every click = spawn 2 actors, but i can't detach or hide or disable that in the hand,
    I want to know :
    How to detach weapon from hand and set it into another socket like back at the photo (or pistol pocket) ..

    ** Before your reply : Search in forum, i saw every content about Weapons-Actors-Sockets.. and there isn't no fix for my problem
    so i want direct solution **

    thanks for every one.
    and sorry for bad english

    #2
    #Fixed
    By using :
    https://www.tomlooman.com/survival-sample-game-for-ue4/
    you can learn.

    Comment


      #3
      Blake thanks for sharing your problem and fix. I went through the same situation. Like everywhere is C++ and equipping but the unequipping is hard to track down.

      Comment

      Working...
      X