WooshiiDev/HierarchyDecorator

Bug - Settings object reference not found

Closed this issue · 8 comments

Vacui commented

Current Unity version used
2018.4.24f1

Describe the bug
After installing the plugin using the .unitypackage provided with the release 0.8.4, I found out that the script is unable to detect the ScriptableObject containing the Settings. A NullRefereceException is printed in the console, originated on the GetOrCreateSettings function.

To Reproduce (If applicable)
The plugin works perfectly fine in a 2018.4.24f1 project, therefore I'm not aware of a way to reproduce this problem.

Screenshots
Screenshot 2021-10-14 at 08 44 15

Additional context
The project I'm working is big and complex, I can't exclude the possibility that this problem is originated by other scripts' behaviours.

Vacui commented

After testing the same problem on a clean project in 2018.4.24f1, and seeing the plugin working perfectly find,I can say the problem is originated from something in my own project.
I will try to uninstall the plugin again, and running a few more tests, to see if the problem persists.

I updated the original post removing the "reproduce" part.

Vacui commented

I found the culprit of the error.
When calling the method AssetUtility.FindOrCreateScriptable, the value passed as type name was "Settings", and I already had a class with that name in another namespace.
To fix the problem I changed the value of the constant SETTINGS_TYPE_STRING in HierarchyDecorator from "Settings" to "HierarchyDecorator.Settings", to avoid the collision.

Hey there Vacui, appreciate the report.
We've had an issue report about a month ago in #40 as it conflicts with FMOD.
I had to take some time away from working on this, but I should have a fix for this within the next few days.

Vacui commented

While working on the fix I found another problem.
The constant SETTINGS_TYPE_STRING is also used to name the Settings file, therefore you have to make this changes if you want to maintain the name:

On HierarchyDecorator.cs

  • add another constant for the name, like
    public const string SETTINGS_NAME = "Settings";
  • change the FindOrCreateScriptable call in
    Settings settings = AssetUtility.FindOrCreateScriptable<Settings> (SETTINGS_TYPE_STRING, SETTINGS_NAME, Constants.SETTINGS_ASSET_FOLDER);

On AssetUtility.cs

  • add the file name to the FindOrCreateScriptable function parameters
    internal static T FindOrCreateScriptable<T>(string type, string name, string createPath, Action<T> onCreate = null) where T : ScriptableObject
  • change the file name when creating the file
    scriptable = CreateScriptableAtPath<T> (name, createPath);

I hope it helps

I've pushed a fix to the branch v0.8.5 in the commit 0053eb7 that fixes this problem.

Now, it checks for the specific setting type - which is something it should have done already - as well as checking all assets named "settings".

I'm not pushing it to the main branch yet as there's some other bugs I want to address but it's available on the branch mentioned above if you want to investigate yourself.

I'll keep this open for the time being until it's pushed to main in case of any problems that crop up.

Vacui commented

It seems it is working for the time being, thx for the quick fix.

Ah fantastic, great to know it's been fixed. I'm sorry it's not on the main branch yet, other work has been busy, will be back on this soon 🙂

Hi Vacui, I've released a fix for this in v0.8.5.
As this seems to be fixed, I'm going to close the issue, however if there's any further issues please feel free to reply to this issue and I'll reopen it 🙂