Search Unity

Question Sword equipped in the wrong place

Discussion in 'Scripting' started by TediMedi, Feb 13, 2024.

  1. TediMedi

    TediMedi

    Joined:
    Oct 20, 2023
    Posts:
    7
    Hi everyone! I've been making a RPG game for a school project. Note that I don't know anything about Unity and C# so I've been following a tutorial (you can find it here: https://youtube.com/playlist?list=PLPV2KyIb3jR4KLGCCAciWQ5qHudKtYeP7&si=WNx-UA_5qHikPEbJ). The armour equips just fine. My problem is that, when I equip the weapon, It's being place in the spine of the character. I've been searching for days and I can't find anything :( I will attach the script and some photos to show you what I mean.
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,727
    I would review where the tutorial tells you to attach it as well as review any offset you might have on the weapon.

    Unity is great this way because you can press PLAY, then PAUSE, then go digging into your scene and find the sword, find what it is attached to, move it to what it SHOULD be attached to, then reason about what code made it go to the wrong place and fix that.

    Remember: tutorials have two steps only:

    - do them perfectly, without fail
    - stop and understand every single part well enough to explain it to your dog (see my avatar)
     
  3. TediMedi

    TediMedi

    Joined:
    Oct 20, 2023
    Posts:
    7


    Hi, yes, but I can't do that because when the item goes into my inventory and I equip, it disappears from the hierarchy :(
     
  4. Nad_B

    Nad_B

    Joined:
    Aug 1, 2021
    Posts:
    730
    No game object disappears from the hierarchy, unless you destroy it. If you can see the game object on the screen, it is in the hierarchy, you just need to find it. Your sword is probably a child of the character (or one of its bones game objects, so it can be really deep in the hierarchy).

    Tip: A simple
    Debug.Log("Sword equipped", swordGameObject)
    will highlight the game object in the hierarchy when the log entry is clicked, making it very easy to find.
     
    Kurt-Dekker likes this.
  5. TediMedi

    TediMedi

    Joined:
    Oct 20, 2023
    Posts:
    7


    When I pick it up from the ground it get's destroyed yes. It goes into my inventory.
     
  6. Nad_B

    Nad_B

    Joined:
    Aug 1, 2021
    Posts:
    730
    You said "when I equip the weapon, It's being place in the spine of the character".

    So you do have a sword game object, probably a clone of the original one you destroyed when your character picks it up, but still a sword game object.
     
  7. TediMedi

    TediMedi

    Joined:
    Oct 20, 2023
    Posts:
    7
    I see, thank you :)
     
  8. TediMedi

    TediMedi

    Joined:
    Oct 20, 2023
    Posts:
    7


    UPDATE: I FIXED IT!! Thanks to everyone who replied :)