Adding New Weapon Items

magique

Active member
I'm trying to add a Two handed Sword item, but the documentation seems incomplete. I have no problem creating the item Type, but the steps for Item Creation assume a couple of things that are not explained anywhere that I can find. Here are the parts that I don't have information on how to do:

Third Person Visible Item: It says this is the actual item model. So, is this just the raw 3D item for the weapon? Or a prefab that has the box collider, trail renderer, etc? If the latter then I don't see any instructions on creating this prefab.

Animator Controller: No where can I find how to create this Animator Controller for my custom weapon. The example uses AssaultRifle, but of course that already exists in the demo resource.

Perhaps the instructions are somewhere else that I couldn't find.
 
So, is this just the raw 3D item for the weapon?
That's correct.

Animator Controller: No where can I find how to create this Animator Controller for my custom weapon. The example uses AssaultRifle, but of course that already exists in the demo resource.
No animator controller is necessary for the sword since it doesn't animate.

This video does a pretty good job of going through in detail how to setup the melee weapons:

 
How do you know which Animator ID to use? If I'm creating a new weapon from a new Item Type, where does that number come from? I've started from a completely new Item Database so does it just start sequentially from 1?
 
Also, in the video it shows a field called Item Parent and you select Items, which is something that is definitely in the character hierarchy. But in the latest TPC, I don't have that selection at all. The first person stuff is not even there. Which is fine I suppose because I'm not using First Person, but just curious as to why it's missing. Is it because I haven't upgraded my UFPS and only upgraded TPC?
 
OK, so I am mostly there. However, when I Build the Item and hit Play, the sword is not visible in the character's hand like in the video. I even tried adding the item to the default loadout, but no success. I see that the new item is under an items parent for the right hand and is also under the main Items hierarchy for the character as well. So, I'm not sure where I went wrong.

Here is a screenshot showing item in hand and you can see the item in the hierarchy twice on the left. Item is called DragonsBane.

1539616660773.png

And here is it when hitting play.
1539616700926.png

I see the item is grayed out. Maybe it needs some flag somewhere to auto equip it? I'll try to find it, but that's where I'm at so far.
 
I talk about the animator id at this time in the video:


The first person options will only be there if you have the First Person Controller. I would follow that video step by step - if there is something different then take a step back to ensure everything is the same.
 
OK, I couldn't find that video. I was looking at your video list in Youtube, but didn't see it. I'll have to go back over that one and see if anything there fixes my issues. I was just using the documentation, which has a lot less information.
 
I've gotten further with this now, but something strange is happening. The sword is equipped and I can even attack with it, but after 1 or sometimes 2 attacks, it no longer functions and the player character just stops animating completely. I move around the world, but he doesn't walk and can't attack anymore. But I don't see any errors. After playing with it a little bit I see that it will continue to work as long as I let a sword attack complete fully. But if I click the attack button multiple times, even while the first attack is playing, then it only performs the attack once and then the model is frozen and can't attack anymore.
 
That sounds related to the combo system - do you have multiple attacks setup? If not try deselecting Allow Combos under the melee weapon.
 
I just set up the melee weapon like the video shows so I didn't change anything in the weapon setup except adjusting the weapon's position in the hand. But I tried unchecking Allow Combos and it didn't help. I used Animator ID 22, which is the already existing Sword state.
 
One thing that I noticed though is that the video said to look for the Animator ID state on the Item Layer, but the Sword isn't on the Item Layer. I found it on the Upper Body Layer. I don't know if that has anything to do with it.
 
I've tried now a couple of times doing the entire process over and I get the same results every time. It should be easily reproducible. If you can't get it, then I will make a video of doing it step by step and maybe you can see what I'm doing wrong.
 
I'm trying to get this working again, but something isn't quite right. I follow the Item Type creation video and the one on creating Melee Weapons, but I see 2 issues. First, I am doing one thing differently. Instead of just adding the Sword to the Items category, I'm creating a Weapons category. I don't see how that's a problem, but maybe it is. Anyway, after I've created my new Sword item, it puts it in the default loadout, but when I hit play it never equips the item. I noticed that the item ends up going into the Items section of item Set Manager even though it's supposed to be in Weapons. However, when I press play then it shows it in both the Items and Weapons sets. And it isn't actually equipped nor can I equip it by pressing the equip button.

I will try again by just putting it in Items category and see what happens. But it seems like there is a bug here.
 
OK, so if I make it in the Items category then it equips. However, when I start swinging the weapon I get the following error:

Texture rectangle is out of bounds (1189 + 1 > 512)
UnityEngine.TerrainData:GetAlphamaps(Int32, Int32, Int32, Int32)
Opsive.UltimateCharacterController.SurfaceSystem.SurfaceManager:GetDominantTerrainTexture(Vector3, Terrain) (at Assets/Opsive/UltimateCharacterController/Scripts/SurfaceSystem/SurfaceManager.cs:799)
Opsive.UltimateCharacterController.SurfaceSystem.SurfaceManager:GetTerrainTexture(Collider, Vector3) (at Assets/Opsive/UltimateCharacterController/Scripts/SurfaceSystem/SurfaceManager.cs:763)
Opsive.UltimateCharacterController.SurfaceSystem.SurfaceManager:GetTerrainSurfaceType(RaycastHit) (at Assets/Opsive/UltimateCharacterController/Scripts/SurfaceSystem/SurfaceManager.cs:729)
Opsive.UltimateCharacterController.SurfaceSystem.SurfaceManager:GetSurfaceType(RaycastHit) (at Assets/Opsive/UltimateCharacterController/Scripts/SurfaceSystem/SurfaceManager.cs:278)
Opsive.UltimateCharacterController.SurfaceSystem.SurfaceManager:GetSurfaceEffect(RaycastHit, SurfaceImpact, SurfaceType&, Boolean&) (at Assets/Opsive/UltimateCharacterController/Scripts/SurfaceSystem/SurfaceManager.cs:250)
Opsive.UltimateCharacterController.SurfaceSystem.SurfaceManager:SpawnEffectInternal(RaycastHit, SurfaceImpact, Vector3, Single, GameObject) (at Assets/Opsive/UltimateCharacterController/Scripts/SurfaceSystem/SurfaceManager.cs:184)
Opsive.UltimateCharacterController.SurfaceSystem.SurfaceManager:SpawnEffect(RaycastHit, SurfaceImpact, Vector3, Single, GameObject) (at Assets/Opsive/UltimateCharacterController/Scripts/SurfaceSystem/SurfaceManager.cs:168)
Opsive.UltimateCharacterController.Items.Actions.MeleeWeapon:HitCollider(MeleeHitbox, Collider) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/MeleeWeapon.cs:595)
Opsive.UltimateCharacterController.Items.Actions.MeleeWeapon:UseItemUpdate() (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/MeleeWeapon.cs:466)
Opsive.UltimateCharacterController.Character.Abilities.Items.Use:LateUpdate() (at Assets/Opsive/UltimateCharacterController/Scripts/Character/Abilities/Items/Use.cs:566)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion:LateUpdateActiveAbilities(Ability[], Int32&) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:843)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion:LateUpdateUltimateLocomotion() (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:831)
Opsive.UltimateCharacterController.Character.CharacterLocomotion:Move(Single, Single, Single) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/CharacterLocomotion.cs:476)
Opsive.UltimateCharacterController.Game.DeterministicCharacter:FixedMove() (at Assets/Opsive/UltimateCharacterController/Scripts/Game/DeterministicObjectManager.cs:146)
Opsive.UltimateCharacterController.Game.DeterministicObjectManager:FixedUpdate() (at Assets/Opsive/UltimateCharacterController/Scripts/Game/DeterministicObjectManager.cs:589)

I should note that the terrain is using a custom shader so this is probably because your system doesn't handle special cases. The weapon is not positioned correctly initially and is hitting the terrain when swinging. I'll switch to a standard shader for now on the terrain and revisit this issue later.

[EDIT]
Maybe not. It seems the error occurs with Standard and Legacy terrain shaders as well.
 
Also, I am still seeing the issue where after 1 or sometimes 2 attacks, it no longer functions and the player character just stops animating completely. I move around the world, but he doesn't walk and can't attack anymore.

And when I have a sword equipped, the left arm goes all wonky. It kind of sticks out stiffly to the side and when I jump it even looks stranger. I'll have to make a video. It's very strange.
 
What does your terrain shader look like? Can you send me the terrain data as well as the material/texture used so I can take a closer look at that error?

Also, I am still seeing the issue where after 1 or sometimes 2 attacks, it no longer functions and the player character just stops animating completely. I move around the world, but he doesn't walk and can't attack anymore.
Make sure the AnimatorAudioState Selector is set to Sequence for the Use field.

And when I have a sword equipped, the left arm goes all wonky. It kind of sticks out stiffly to the side and when I jump it even looks stranger. I'll have to make a video. It's very strange.
This is probably related to IK. If you add the Sword state it should look better. If not does disabling the CharacterIK component help?
 
This is probably related to IK. If you add the Sword state it should look better. If not does disabling the CharacterIK component help?
I think now it might have to do with the character model I'm using. I tried with Nolan character and didn't have the issue. My character model doesn't come in T-Pose so maybe that's an issue? I'll investigate further.

What does your terrain shader look like? Can you send me the terrain data as well as the material/texture used so I can take a closer look at that error?
I tried again with Standard and Legacy shaders and the same issue happened.

Make sure the AnimatorAudioState Selector is set to Sequence for the Use field.
I'll give this a try.
 
I don't understand the AnimatorAudioState instructions. I don't see anything like Use field or Sequence or Selector.

1542243570584.png
 
My character model doesn't come in T-Pose so maybe that's an issue?
You'll need to ensure all of your character's bones are mapped.
I don't understand the AnimatorAudioState instructions. I don't see anything like Use field or Sequence or Selector.
This page gives a complete example of how they are used - take a look at the combos section: https://opsive.com/support/document...-controller/items/actions/usable/melee-weapon. The Use Animator Audio State is within the first Use foldout of the MeleeWeapon component.
 
OK, so I found the place to set the Animator Audio State to Sequence, but it doesn't help. If I click to attack during an attack in progress it still works fine, but if I rapidly click the left mouse button all during the attack then that's when it fails. I examined Nolan from the demo scene and it has the additional Audio State, but if I remove that state then I get a similar failure. After rapidly clicking the left mouse button then Nolan just gets stuck in place and can't even move. So I added the second audio state in my character just like Nolan and the problem goes away.
 
Top