Can We Use Struct class?

Discuss modding questions and implementation details.
l3lessed
Posts: 1400
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Can We Use Struct class?

Post by l3lessed »

I'm compiling my compass mod for stand alone DFU. However, on loading it in a stand alone, the log is giving me an error around using a struct type var and failing to load the mod.

Can we use "struct" classes?

Here is the structure class code creating the issue; I'm loading this into a list to store, as it says, marker info for each individual marker I build and place.

Code: Select all

        // meta data for building markers used for looping through and updating individual building marker properties.
        public struct MarkerInfo
        {
            public GameObject attachedMesh;
            public GameObject attachedLabel;
            public GameObject attachedIcon;
            public BuildingSummary buildingSummary;
            public DFLocation.BuildingTypes buildingType;
            public int buildingKey;
            public Vector3 position;
            public Color iconColor;
            public MarkerGroups iconGroup;
            public bool iconActive;
        }
Here is the specific error:
System.TypeLoadException: Invalid type DaggerfallWorkshop.Game.Minimap.Minimap/MarkerInfo[] for instance field System.Collections.Generic.List`1[DaggerfallWorkshop.Game.Minimap.Minimap+MarkerInfo]:_items
at (wrapper managed-to-native) System.RuntimeType.GetCorrespondingInflatedConstructor(System.RuntimeType,System.Reflection.ConstructorInfo)
at System.RuntimeType.GetConstructor (System.Reflection.ConstructorInfo fromNoninstanciated) [0x00014] in <fb001e01371b4adca20013e0ac763896>:0
at System.Reflection.Emit.ConstructorOnTypeBuilderInst.RuntimeResolve () [0x0000b] in <fb001e01371b4adca20013e0ac763896>:0
at System.Reflection.Emit.ModuleBuilder.RuntimeResolve (System.Object obj) [0x00080] in <fb001e01371b4adca20013e0ac763896>:0
at (wrapper managed-to-native) UnityEngine.GameObject.Internal_AddComponentWithType(UnityEngine.GameObject,System.Type)
at UnityEngine.GameObject.AddComponent (System.Type componentType) [0x00001] in <548b4fa0e7e04f27a1b7580930bfb7dc>:0
at UnityEngine.GameObject.AddComponent[T] () [0x00001] in <548b4fa0e7e04f27a1b7580930bfb7dc>:0
at DaggerfallWorkshop.Game.Minimap.Minimap.Init (DaggerfallWorkshop.Game.Utility.ModSupport.InitParams initParams) [0x0000b] in <78d967d110834cfa90d4a0b41766673d>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <fb001e01371b4adca20013e0ac763896>:0
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 35)
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
numidium3rd
Posts: 187
Joined: Sun Mar 25, 2018 12:34 am
Location: United States

Re: Can We Use Struct class?

Post by numidium3rd »

I found another post that mentions issues the mod compiler has with structs. Looks like you'll have to use a class, unfortunately.

l3lessed
Posts: 1400
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Can We Use Struct class?

Post by l3lessed »

Thanks for verifying that. Yeah, was thinking about it at the gym, and I decided going with a proper constructor class to attach to objects would be a better and more efficient approach anyways, especially when the player updates their indicator preferences. Also, it will make grabbing and using building indicators easier for future code changes and other modders.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 1400
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Can We Use Struct class?

Post by l3lessed »

Okay, removed the struct classes and created a buildingMarker class constructor in place.

Next question. I'm using enums, so I'm using the experimental build mod, which if I understand correct allows enums. However, I am now getting this error on trying to load the mod.
No mod loaders found for mod: Minimap
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 35)
I know I'm probably messing up the compile process under the experimental option.

Okay, I found the documentation on how this is supposed to be done. It requires setting up a custom project environment to compile the dll to add to the build package.

viewtopic.php?f=23&t=3498&p=41212&hilit ... led#p41212
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
Hazelnut
Posts: 3015
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Can We Use Struct class?

Post by Hazelnut »

numidium3rd wrote: Wed May 19, 2021 11:30 pm I found another post that mentions issues the mod compiler has with structs. Looks like you'll have to use a class, unfortunately.
Using the pre-compile option should avoid all the issues that the mod compiler mcs has, and should allow structs to be used. Well that's what I thought anyway.


Not sure what is requiring a custom anything related to DLLs, I thought that pre-compilation worked without needing any changes to the mod code structure.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

User avatar
numidium3rd
Posts: 187
Joined: Sun Mar 25, 2018 12:34 am
Location: United States

Re: Can We Use Struct class?

Post by numidium3rd »

Hazelnut wrote: Thu May 20, 2021 9:50 am Using the pre-compile option should avoid all the issues that the mod compiler mcs has, and should allow structs to be used. Well that's what I thought anyway.
I've been away for too long - haven't heard of this pre-compile option until now. Glad we have a way around all the mod compiler issues.

User avatar
DunnyOfPenwick
Posts: 275
Joined: Wed Apr 14, 2021 1:58 am
Location: Southeast US

Re: Can We Use Struct class?

Post by DunnyOfPenwick »

Since we're on the subject, I've had issues with C# version issues before. The Unity engine used by DFU uses a C# version 6 compiler when loading mods, but the Unity IDE uses the latest installed version of C#. Whenever I used language features that weren't available in v6, the engine would fail to load/compile the mod.

The way I got around the problem was by closing Unity and modifying the generated *.csproj files to specifically use version 6, as in "<LangVersion>6</LangVersion>" and opening the project directly in Visual Studio. This allowed me to more readily identify any compiler issues.

I think newer versions of Unity have a setting for specifying the C# lanaguage version to be used.

Speaking of versions, what is the technical reason that we have to use Unity 2019.4.10?

l3lessed
Posts: 1400
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Can We Use Struct class?

Post by l3lessed »

Using the pre-compile option should avoid all the issues that the mod compiler mcs has, and should allow structs to be used. Well that's what I thought anyway.


Not sure what is requiring a custom anything related to DLLs, I thought that pre-compilation worked without needing any changes to the mod code structure.
I'm sure the compiler works fine. I wasn't trying to say it wasn't, just poor wording. I didn't try the precompile approach with the struct classes in the mod; I opted for just removing them and putting them all under a single constructor class. After I moved them over to a single constructor class is when I decided I should setup the proper precompile process because I don't want to lose my enums.

I'm going to spend a little time right now seeing if I can get the project setup properly to create the dll needed for the precompile version.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
pango
Posts: 3347
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Can We Use Struct class?

Post by pango »

DunnyOfPenwick wrote: Thu May 20, 2021 3:08 pm Speaking of versions, what is the technical reason that we have to use Unity 2019.4.10?
2019.4.25 will be necessary for localization system
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
Hazelnut
Posts: 3015
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Can We Use Struct class?

Post by Hazelnut »

l3lessed wrote: Thu May 20, 2021 5:13 pm I'm going to spend a little time right now seeing if I can get the project setup properly to create the dll needed for the precompile version.
Good luck. I was just trying to say all I thought was needed was to check the pre-compile option on mod builder screen.. but I guess there's something more for what you're doing. Looking forward to trying this out. :)
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

Post Reply