[BUG] Script execution order using Inventory instead of InventoryBase

Sangemdoko

Moderator
Staff member
Hi,

I am using TPC 2.1.1 and Unity 2018.3.6f1

I updated to version 2.1.1 this morning and I have some issues.

I have my own InventoryBase extension, therefore I don't use the Inventory script. My problem is that my custom inventory Awake method is called after the AnimatorMonitor Awake method.
1551532154890.png
I have never used the script execution order setting, so I thought maybe I could have fixed the problem by replacing Inventory by InventoryBase.

I tried this
1551532664652.png

It didn't work. I assume it is because of the script execution order doesn't take into account base/inherited classes.

So I tried adding my custom inventory in the script execturion order setting:
1551533340935.png

Doing so fixed some issues but not all. For some reason the m_AnimatorAudioStateSelector variable in the AnimatiorAudioStateSet script is null, but I'll have to dig in more to understand why.

I am not sure how you would fix the script execution order for anyone that has their own inventoryBase extension. Maybe the only way would be to have a "How to extend the inventory" section in the documentation that specifies the steps you need to take.
 
I found out that the m_AnimatorAudioStateSelector variable was null because the deserialize function would return null:

C#:
m_AnimatorAudioStateSelector = m_AnimatorAudioStateSelectorData.DeserializeFields(MemberVisibility.Public) as AnimatorAudioStateSelector;

I am using a custom class (WeaponItem) that inherits from Item. And it didn't have the editor inspector that was serializing the animatorAudioStateSelectorData. So I added this editor script:

C#:
using UnityEditor;
using Opsive.UltimateCharacterController.Editor.Inspectors.Items;
using SleepingPenguinz.PhaeProject.Inventory;

namespace SleepingPenguinz.PhaeProject.Inspectors
{
    [CustomEditor(typeof(WeaponItem))]
    public class WeaponItemInspector : ItemInspector
    {
    }
}

And it fixed my problems.

I think it would be worth considering an alternative option for the serialization for people that might want to create an Item component at run time. Also now I wouldn't know how I would add my custom class properties in the inspector, because the ItemInspector scripts update the inspector view in an uncommon way (I'm not used to writing editor code yet).
 
Top