Items are objects that the character can carry, ranging from a flashlight to a rocket launcher. Items can be created from the Item Manager which can be opened from the Tools -> Ultimate Character Controller -> Items Manager menu option.
Start to fill in the following fields:
- Name: MyAssaultRifle
- Item Type: MyAssaultRifle. This is the ItemType that was created on this page.
- Character: Nolan. This is the same character that was created on this page.
- Animator Item ID: 1. This number matches the ItemID parameter within the Animator Controller. Default values are located on this page.
The next step depends on if you are creating a first or third person item. If your character is going to be an AI agent or part of a multiplayer game the Third Person Visible Item field should be specified even if your game is a first person game.
For an item used in the first person perspective the following fields should be filled out:
- First Person Base: NolanFirstPersonArms. This object is rendered on the screen holding the object. This is normally the character’s arms. This should be a separate object so it can be activated independently of the base character model. Items can use existing First Person Objects or create a new object can be used for each item. In most cases it is easier to use an existing object for multiple items. This object should be dragged into the scene so it can be modified before the item is built.
- First Person Base Animator Controller: FirstPersonArmsDemo. This is the Animator Controller that the First Person Object uses. This Animator Controller should have the same parameters as the Animator Controller used by the base character. This field will not be visible if the First Person Object has already been setup by the Item Manager.
- First Person Visible Item: AssaultRifle. This is the actual item model.
- Item Parent: ORG-hand_R. This is our character’s right hand, a child of the First Person Object. This is the object that the First Person Visible Item will be parented to.
- Animator Controller: AssaultRifle. This is the Animator Controller that is added to the item and will show the assault rifle being used or reloaded.
Before we can continue the Visible Item must be parented to an ItemSlot so the inventory knows which item to equip/unequip. Once the Add ItemSlot button is pressed a new “Items” GameObject will be created and the First Person Visible Item will use that new GameObject for the Item Parent. Ensure your First Person Base object is within the scene in order to be able to add the ItemSlot.
The remaining first person field, First Person Visible Item Animator Controller, specifies the Animator Controller that the visible item should use. This Animator Controller will animate the assault rifle (such as when it is fired).
Third person items are parented to the actual character model so they are easier to setup:
- Third Person Visible Item: AssaultRifle. This is the actual item model.
- Third Person Hand: Right. This is the object that the Third Person Object is parented to. If the character is not humanoid then the object needs to be manually specified.
- Third Person Animator Controller: AssaultRifle. This is the Animator Controller that is added to the item and will show the assault rifle being used or reloaded. It is optional but adds a nice polish to the third person view.
The last section that needs to be specified relates to the action types. Actions perform the actual interaction with the item, such as firing a bullet or slashing a sword. Multiple actions can be added to a single item but for this example we just want the item to shoot so the following values can be specified:
- Action Type: Shootable Weapon. The assault rifle should be able to shoot bullets.
- Consumable Item Type: MyAssaultRifleBullet. This is the same ItemType that was previously created.
The State Configuration field can be left blank. Once you have filled in all of the field values the builder should look like:
Go ahead and click “Build Item”. You’ll notice that the assault rifle has now been added to the character, but it is positioned incorrectly in both the first and third person character’s hand.
The item position can be adjusted by pressing play within Unity and adjusting the position and rotation of the item’s transform component. Once you stop playing you can then paste the values back into the Transform component. Here are the values that we are using for the assault rifle:
This transform is set on the actual Assault Rifle object located underneath the character’s rig or arms hierarchy. The first person assault rifle is located at: Nolan/First Person Objects/NolanFirstPersonArms/rig/ORG-shoulder_R/ORG-upper_arm_R/ORG-forearm_R/ORG-hand_R/Items/MyAssaultRifle. The third person assault rifle has a similar path: Nolan/rig/root/ORG-hips/ORG-spine/ORG-chest/ORG-shoulder_R/ORG-upper_arm_R/ORG-forearm_R/ORG-hand_R/Items/MyAssaultRifle.
After you hit play the assault rifle will be positioned correctly, but it will be in the incorrect location for the first person view. This is because the new assault rifle item controls the location of the first person arms (the First Person Object value from the Item Builder) and the default location probably won’t fit your new item. This can be adjusted within the First Person Perspective Item component of the MyAssaultRifle object under Nolan/Items/MyAssaultRifle. Most of the properties that you edit for the assault rifle will be located on this object. In this case we want to adjust the Position Offset and Position Exist Offset to:
Now when you hit play the assault rifle should be positioned correct for both first and third person! Further details on the Item Manager can be found on this page.