[Solved] ModManager.Instance.TryGetAsset fails from within Mod

Discuss modding questions and implementation details.
Post Reply
User avatar
AncientGrief
Posts: 4
Joined: Wed Jun 22, 2022 8:28 am
Location: Germany

[Solved] ModManager.Instance.TryGetAsset fails from within Mod

Post by AncientGrief »

Hi,

I am new here :) (I posted the in the wrong subforum before x_X)

EDIT: Solved. I used a C# feature which apparently works in Unity 2019 but ofc not with FsSerializer...

I created a class inheriting from MobilePersonAsset and added it as a component to a Prefab called MobilePersonAsset, like explained here: https://www.dfworkshop.net/projects/dag ... son-assets

It all works pretty well, but when running the mod outside of the Unity Editor I get these error messages:

Code: Select all

Deserialization of MobilePersonAsset from TestMod failed with messages:
Failed to find type MyCustomMobilePerson. 
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)

Failed to retrieve MobilePersonAsset component from GameObject. 
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)
The prefab has only this script attached to it. Maybe someone knows what I am missing here :/
I already removed the namespace but that doesn't seem to be the error. Maybe the [ImportedComponent] Attribute is the culprit or me not knowing about a special rule regarding the serialization of Components added via the editor?

Edit:
Okay I found the issue, after deleting a lot of my code and debugging with the build mod inside Unity I got it down to this error message (I don't really know why though) and the mod loading:

Code: Select all

Ignoring type specifier; a field/property of type MyCustomMobilePerson cannot hold an instance of MyCustomMobilePerson
I deleted this line from within my SetPerson-Method:

Code: Select all

if (ModManager.Instance && ModManager.Instance.TryGetAsset(prefabName, true, out GameObject prefab3D))
This line is crucial, I need to load another prefab from another mod, is there any other way to achieve this?!

The error gets thrown in fsSerializer.TryDeserialize() in ImportedComponentAttribute.cs when using TryGetAsset(). I am not familiar with FsSerializer and why it has a problem with the content of my method while deserializing. x_X

Post Reply