Help wanted! Loading prefab into scene. Mod showsup in mod menu, doesnt load in scene.

Discuss modding questions and implementation details.
Post Reply
User avatar
gunsling3r
Posts: 25
Joined: Sun Dec 01, 2019 2:45 am

Help wanted! Loading prefab into scene. Mod showsup in mod menu, doesnt load in scene.

Post by gunsling3r »

.


I think its a very common issue but I have yet to find a solution. I have been through tutorials and aren't even able to successfully complete tutorials.

I have a test.dfmod file inside StreamingAssets/Mods folder.
I have test.dfmod.json file under Assets\Game\Mods
I have original mod content I used to make mod is under Assets\Untracked\Minimap

I have this so far:
Mod works under unity scene where it was developed. All its gameobjects are disabled when testing loading of mod.
Mod shows up under mod menu.
Mod is not loaded into scene while playing game under unity.

I am using a script from Example3, this script should load my gameobject prefab into game using this, see very last lines in below code.

Code: Select all

using UnityEngine;
using System.Collections;
using DaggerfallWorkshop.Game;
using DaggerfallWorkshop.Game.Utility.ModSupport;

namespace DaggerfallModdingTutorials.Part3
{
    //this class initializes the mod.
    public class MinimapModLoader
    {
        public static Mod mod;
        public static GameObject ExampleGo;

        //like in the last example, this is used to setup the Mod.  This gets called at Start state.
        [Invoke]
        public static void InitAtStartState(InitParams initParams)
        {
            mod = initParams.Mod;

            Debug.Log("Started setup of : " + mod.Title);

            //start loading all assets asynchrousnly - the bool paramater tells it to unload the asset bundle since all assets are loaded
            ModManager.Instance.GetComponent<MonoBehaviour>().StartCoroutine(mod.LoadAllAssetsFromBundleAsync(true));

            mod.IsReady = true;
        }

        [Invoke(StateManager.StateTypes.Game)]
        public static void InitAtGameState(InitParams initParams)
        {
            if (ExampleGo != null)
                return;
            //Get a clone of the example gameobject prefab from mod

            ExampleGo = mod.GetAsset<GameObject>("Canvas.prefab", true);  //fetches gameobject and puts in scene
	//ExampleGo = mod.GetAsset<GameObject>("MINIMAP.prefab", true);
	
	
        }
    }
}
I see these under console.

Code: Select all

Ignoring virtual mod test because release mod is already loaded.
Error (): `UnityEngine.UIElements.BaseField<TValueType>' must be type definition or nested non-inflated type to MakeGenericType
added asset: test.dfmod.json
added asset: minimapmodloader.cs.txt
Finished Mod setup: test
ModManager - started loading mod: test
I have these files I used to make mod. I do not know if I need to add these to a script to load them.
At the moment I am simply fetching prefab using Example3 script from tutorial. The prefab has everything inside setup to use these files to show a functional minimap. I have done everything with no luck.
Image


Any guidance is welcome, you can contact me here discord: gunsling3r#6099 to quickly reach me.
This is actually what I am working on, a Minimap mod viewtopic.php?f=14&t=3098



.
Last edited by gunsling3r on Sun Dec 01, 2019 5:35 pm, edited 3 times in total.

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

Re: Mod shows up under mod menu, doesnt work under game.

Post by Hazelnut »

Without being able to see your C# code I can't help. No idea how to get prefabs into mods either, sorry.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods


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

Re: Help wanted! Loading prefab into scene. Mod showsup in mod menu, doesnt load in scene.

Post by pango »

Have you tried instantiating the prefab to create your gameObject?
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
TheLacus
Posts: 1305
Joined: Wed Sep 14, 2016 6:22 pm

Re: Help wanted! Loading prefab into scene. Mod showsup in mod menu, doesnt load in scene.

Post by TheLacus »

gunsling3r wrote: Sun Dec 01, 2019 3:46 am I have a test.dfmod file inside StreamingAssets/Mods folder.
I have test.dfmod.json file under Assets\Game\Mods
I have original mod content I used to make mod is under Assets\Untracked\Minimap
gunsling3r wrote: Sun Dec 01, 2019 3:46 am

Code: Select all

Ignoring virtual mod test because release mod is already loaded.
You have two different mods with the same GUID. One mod is created from individual files inside Assets/Game/Mods, the other is the .dfmod file inside StreamingAssets. The latter overrides the first, so any change you make to files are not used until you rebuild the mod (or remove it).

gunsling3r wrote: Sun Dec 01, 2019 3:46 am I have this so far:
Mod works under unity scene where it was developed. All its gameobjects are disabled when testing loading of mod.
Mod shows up under mod menu.
Mod is not loaded into scene while playing game under unity.

I am using a script from Example3, this script should load my gameobject prefab into game using this, see very last lines in below code.

Code: Select all

using UnityEngine;
using System.Collections;
using DaggerfallWorkshop.Game;
using DaggerfallWorkshop.Game.Utility.ModSupport;

namespace DaggerfallModdingTutorials.Part3
{
    //this class initializes the mod.
    public class MinimapModLoader
    {
        public static Mod mod;
        public static GameObject ExampleGo;

        //like in the last example, this is used to setup the Mod.  This gets called at Start state.
        [Invoke]
        public static void InitAtStartState(InitParams initParams)
        {
            mod = initParams.Mod;

            Debug.Log("Started setup of : " + mod.Title);

            //start loading all assets asynchrousnly - the bool paramater tells it to unload the asset bundle since all assets are loaded
            ModManager.Instance.GetComponent<MonoBehaviour>().StartCoroutine(mod.LoadAllAssetsFromBundleAsync(true));

            mod.IsReady = true;
        }

        [Invoke(StateManager.StateTypes.Game)]
        public static void InitAtGameState(InitParams initParams)
        {
            if (ExampleGo != null)
                return;
            //Get a clone of the example gameobject prefab from mod

            ExampleGo = mod.GetAsset<GameObject>("Canvas.prefab", true);  //fetches gameobject and puts in scene
	//ExampleGo = mod.GetAsset<GameObject>("MINIMAP.prefab", true);
	
	
        }
    }
}
I see these under console.

Code: Select all

Ignoring virtual mod test because release mod is already loaded.
Error (): `UnityEngine.UIElements.BaseField<TValueType>' must be type definition or nested non-inflated type to MakeGenericType
added asset: test.dfmod.json
added asset: minimapmodloader.cs.txt
Finished Mod setup: test
ModManager - started loading mod: test
I have these files I used to make mod. I do not know if I need to add these to a script to load them.
At the moment I am simply fetching prefab using Example3 script from tutorial. The prefab has everything inside setup to use these files to show a functional minimap. I have done everything with no luck.
Image
The prefab is loaded from mod but you're not doing anything with it beside instantiating it at root. Without other informations it's hard to say what should happen and why it doesn't happen. The log shows an error about UnityEngine.UIElements.BaseField<TValueType>, can you check where is generated?

User avatar
gunsling3r
Posts: 25
Joined: Sun Dec 01, 2019 2:45 am

Re: Help wanted! Loading prefab into scene. Mod showsup in mod menu, doesnt load in scene.

Post by gunsling3r »

The prefab is loaded from mod but you're not doing anything with it beside instantiating it at root. Without other informations it's hard to say what should happen and why it doesn't happen. The log shows an error about UnityEngine.UIElements.BaseField<TValueType>, can you check where is generated?
I have a prefab under Canvas, and with the script provided under tutorial Example3 , I am trying to load it in scene (I suspect that I am not able to properly fetch it as a child of Canvas hence in the script you see me deleting Canvas originaly in scene and fetching my Canvas prefab instead to get around that). Just like how Example3 was loading a prefab into scene, I am trying to do same. My prefab once in scene will fetch its files automatically and should display the mod. My prefab has 2 gameobjects.

User avatar
TheLacus
Posts: 1305
Joined: Wed Sep 14, 2016 6:22 pm

Re: Help wanted! Loading prefab into scene. Mod showsup in mod menu, doesnt load in scene.

Post by TheLacus »

gunsling3r wrote: Sun Dec 01, 2019 10:02 pm
The prefab is loaded from mod but you're not doing anything with it beside instantiating it at root. Without other informations it's hard to say what should happen and why it doesn't happen. The log shows an error about UnityEngine.UIElements.BaseField<TValueType>, can you check where is generated?
I have a prefab under Canvas, and with the script provided under tutorial Example3 , I am trying to load it in scene (I suspect that I am not able to properly fetch it as a child of Canvas hence in the script you see me deleting Canvas originaly in scene and fetching my Canvas prefab instead to get around that). Just like how Example3 was loading a prefab into scene, I am trying to do same. My prefab once in scene will fetch its files automatically and should display the mod. My prefab has 2 gameobjects.
I'll reply only here to keep discussion in a single place. Let's go back to the beginning 😉
  • Download example 3, without making any change. Exctract it to a subfolder of Assets.
  • Open Mod Builder and select example3.dfmod.json.
  • Click Clear All Assets. Now select all the assets in the extracted folder and click Add Selected Assets.
  • Click Build Mod and copy the generated .dfmod file inside Assets/StreamingAssets/Mods.
  • Set DaggerfallUnityStartup as active scene, play and load a save. When you click Pause you can find a gameobject named Example (clone) in the hierarchy.
The issue with the prefab from your mod is probably due to deserialization of custom scripts. See my previous PM on this:
If the prefab has custom scripts you will need to use the ImportedComponentAttribute to correclty deserialize them, while any type found from Unity or Daggerfall Unity asemblies will work as is.
gunsling3r wrote: I also see this under console.
"InvokeModLoaders() finished...time: 4"
"No mod loaders found for mod: Example3-Loading & Setup"
Make sure that ExampleModLoader.cs is added to the mod and that you are using DaggerfallUnityStartup scene.

User avatar
gunsling3r
Posts: 25
Joined: Sun Dec 01, 2019 2:45 am

Re: Help wanted! Loading prefab into scene. Mod showsup in mod menu, doesnt load in scene.

Post by gunsling3r »

So I kept getting these errors whenever I loaded mods from StreamingAssets folder under unity.

Code: Select all

Error (): `UnityEngine.UIElements.BaseField<TValueType>' must be type definition or nested non-inflated type to MakeGenericType
This error was pointing Modbuilder script to no specific line.

Also I was using 2019 version of unity3d so I am now downloading 2018.2.21f1 to rebuild test mod files to see if they work.

User avatar
gunsling3r
Posts: 25
Joined: Sun Dec 01, 2019 2:45 am

Re: Help wanted! Loading prefab into scene. Mod showsup in mod menu, doesnt load in scene.

Post by gunsling3r »

I was able to fix this error.

Code: Select all

Error (): `UnityEngine.UIElements.BaseField<TValueType>' must be type definition or nested non-inflated type to MakeGenericType
I was also able to successfully output a .dfmod file that will appear under game both in unity scene and in actual Daggerfall DFU game.

The solution is to use unity3d version UNity 2018.2.21 when building mods.



The error pointed to modbuilder script to no specific line of code, also modbuilder wasnt properly outputting a .dfmod file as it wasnt visible under mods menu in actual DFU game or streaming folder under unity3d project. Everything else worked fine in Unity 2019, except modbuilder doesnt work well with it, use 2018 version shown above.
Last edited by gunsling3r on Tue Dec 10, 2019 2:01 am, edited 1 time in total.

User avatar
Jay_H
Posts: 4073
Joined: Tue Aug 25, 2015 1:54 am
Contact:

Re: Help wanted! Loading prefab into scene. Mod showsup in mod menu, doesnt load in scene.

Post by Jay_H »

Indeed. In TheLacus' topic for mod documentation, he explains the need ;)
TheLacus wrote: Sat Sep 14, 2019 1:12 pm Download Unity 2018.2.21. Other versions are not compatible.

Post Reply