weapon for first-person-view character without "body"

Absent83

Member
Hallo !
Can you explain, how to setup weapon for first-person-view character without "body" (model and animator controller)?

Does "Ultimate Character Controller" have any limitaions to configure character?

1539360350010.png

after button:

MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.

UnityEngine.GameObject.GetComponent[NavMeshAgent] () (at C:/buildslave/unity/build/artifacts/generated/common/runtime/GameObjectBindings.gen.cs:38)
Opsive.UltimateCharacterController.Editor.Managers.CharacterManager.DrawNewCharacter () (at Assets/Opsive/UltimateCharacterController/Editor/Managers/CharacterManager.cs:341)
Opsive.UltimateCharacterController.Editor.Managers.CharacterManager.OnGUI () (at Assets/Opsive/UltimateCharacterController/Editor/Managers/CharacterManager.cs:173)
Opsive.UltimateCharacterController.Editor.Managers.MainManagerWindow.OnManagerGUI () (at Assets/Opsive/UltimateCharacterController/Editor/Managers/MainManagerWindow.cs:394)
Opsive.UltimateCharacterController.Editor.Managers.MainManagerWindow.OnGUI () (at Assets/Opsive/UltimateCharacterController/Editor/Managers/MainManagerWindow.cs:297)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:295)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:288)
UnityEditor.HostView.InvokeOnGUI (Rect onGUIPosition) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:255)


1539360934109.png

after button:

IndexOutOfRangeException: Array index is out of range.
Opsive.UltimateCharacterController.Utility.Builders.ItemBuilder.BuildItem (System.String name, Opsive.UltimateCharacterController.Inventory.ItemType itemType, Int32 animatorItemID, UnityEngine.GameObject character, Int32 slotID, Boolean addToDefaultLoadout, UnityEngine.GameObject firstPersonObject, UnityEngine.RuntimeAnimatorController firstPersonObjectAnimatorController, UnityEngine.GameObject firstPersonVisibleItem, Opsive.UltimateCharacterController.Items.ItemSlot firstPersonItemSlot, UnityEngine.RuntimeAnimatorController firstPersonVisibleItemAnimatorController, UnityEngine.GameObject thirdPersonObject, Opsive.UltimateCharacterController.Items.ItemSlot thirdPersonItemSlot, UnityEngine.RuntimeAnimatorController thirdPersonObjectAnimatorController, UnityEngine.Material invisibleShadowCasterMaterial, ActionType actionType, Opsive.UltimateCharacterController.Inventory.ItemType actionItemType) (at Assets/Opsive/UltimateCharacterController/Scripts/Utility/Builders/ItemBuilder.cs:116)
Opsive.UltimateCharacterController.Editor.Managers.ItemManager.DrawNewItem () (at Assets/Opsive/UltimateCharacterController/Editor/Managers/ItemManager.cs:265)
Opsive.UltimateCharacterController.Editor.Managers.ItemManager.OnGUI () (at Assets/Opsive/UltimateCharacterController/Editor/Managers/ItemManager.cs:109)
Opsive.UltimateCharacterController.Editor.Managers.MainManagerWindow.OnManagerGUI () (at Assets/Opsive/UltimateCharacterController/Editor/Managers/MainManagerWindow.cs:394)
Opsive.UltimateCharacterController.Editor.Managers.MainManagerWindow.OnGUI () (at Assets/Opsive/UltimateCharacterController/Editor/Managers/MainManagerWindow.cs:297)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:295)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:288)
UnityEditor.HostView.InvokeOnGUI (Rect onGUIPosition) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:255)
 
Last edited:
That setup looks like it should work - I just tried it with version 2.0.3 and didn't get any errors. Have you tried a fresh project?
 
Yes, it was in old test-project... Im sorry.

But I have already checked in v.2.0.3 in Unity 2017.3.1p1 (64-bit)
There was no error during character and item building, but I had an error after scene start:

IndexOutOfRangeException: Array index is out of range.

Opsive.UltimateCharacterController.Inventory.Inventory.AddItemInternal (Opsive.UltimateCharacterController.Items.Item item) (at Assets/Opsive/UltimateCharacterController/Scripts/Inventory/Inventory.cs:49)
Opsive.UltimateCharacterController.Inventory.InventoryBase.AddItem (Opsive.UltimateCharacterController.Items.Item item, Boolean immediateEquip) (at Assets/Opsive/UltimateCharacterController/Scripts/Inventory/InventoryBase.cs:127)
Opsive.UltimateCharacterController.Items.Item.Start () (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Item.cs:262)



1539383968587.png
 
Last edited:
In your other post it didn't look like you added the item components to the character - make sure you add those components to ensure it adds the inventory component.
 
Thank you!
You are right, I forgot to add "inventory" component.

But now I have another error during item building:


1539603066666.png

1539603088209.png

[Exception] NullReferenceException: Object reference not set to an instance of an object
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.


FirstPersonPerspectiveItem.RefreshSprings() Assets/Opsive/UltimateCharacterController/FirstPersonController/Scripts/Items/FirstPersonPerspectiveItem.cs:718
716: m_PositionSpring.RestValue = m_UseSpringExitOffset ? m_PositionExitOffset : m_PositionOffset;
717: m_RotationSpring.RestValue = m_UseSpringExitOffset ? m_RotationExitOffset : m_RotationOffset;
-->718: m_PivotPositionSpring.RestValue = m_PivotPositionOffset;
719: m_PivotRotationSpring.RestValue = (m_LeanTilt * Vector3.forward) + m_PivotRotationOffset;
720: }


FirstPersonPerspectiveItem.set_PositionSpring() Assets/Opsive/UltimateCharacterController/FirstPersonController/Scripts/Items/FirstPersonPerspectiveItem.cs:140
138: set {
139: m_PositionSpring = value;
-->140: if (m_PositionSpring != null) { m_PositionSpring.Initialize(false, true); RefreshSprings(); }
141: }
142: }
 
Last edited:
Thanks for the bug report. Open ItemBuilder and change line 126 from:

Code:
var slots = new ItemType[inventory.SlotCount];
to:

Code:
var slots = new ItemType[Mathf.Max(inventory.SlotCount, item.SlotID + 1)];

You'll also need to add the following to the top of FirstPersonPerspectiveItem.RefreshSprings:

Code:
        private void RefreshSprings()
        {
            if (!Application.isPlaying) { // HERE
                return;  // HERE
            } // HERE
 
Thank you for the fast answer!

Can you say, does the option "Animator Item ID" in the "New item window" have any reason in the case of first-person-view character without "body" (mesh and animator).
What value should I set in this case?
 
Let me know if you are able to reproduce it and then I can take a closer look.
Can you say, does the option "Animator Item ID" in the "New item window" have any reason in the case of first-person-view character without "body" (mesh and animator).
What value should I set in this case?
Yes - this same item id is used in the weapon's animator monitor. This video gives an overview of how the item id is used in the animator:

 
It looks like the controller is trying to activate the third person item. What does your ultimate character locomotion component look like?
 
When I tried those steps I'm not able to reproduce the error. Does your assault rifle have the third person perspective item added to it?
 
Top