[Solved] Black screen and NullReferenceException error by replacing door model

Discuss modding questions and implementation details.
User avatar
XJDHDR
Posts: 258
Joined: Thu Jan 10, 2019 5:15 pm
Location: New Zealand
Contact:

[Solved] Black screen and NullReferenceException error by replacing door model

Post by XJDHDR »

I'm not sure if this is the right place for this but I want to first check if I have done something wrong before assuming it is a bug.

I am trying to modify the model for a door. I made the changes I wanted in Blender, exported it into an OBJ (also tried FBX but that gave me the same problem), set it up in Unity and created a dfmod. However, when I either start a new game or load a save in an area with that door present, the screen freezes up in some way. I have encountered a black screen with only messages and the interaction icon appearing after loading a save. When I started a new game, I appeared to be stuck in the void.

I looked through output_log.txt and found this error:

Code: Select all

NullReferenceException: Object reference not set to an instance of an object
  at DaggerfallWorkshop.Utility.RDBLayout.AddActionDoor (DaggerfallWorkshop.DaggerfallUnity dfUnity, UInt32 modelId, RdbObject obj, UnityEngine.Transform parent, UInt64 loadID) [0x00000] in <filename unknown>:0 
  at DaggerfallWorkshop.Utility.RDBLayout.AddActionDoors (UnityEngine.GameObject go, System.Collections.Generic.Dictionary`2 actionLinkDict, DaggerfallConnect.DFBlock& blockData, System.Int32[] textureTable, Boolean serialize) [0x00000] in <filename unknown>:0 
  at DaggerfallWorkshop.Utility.GameObjectHelper.CreateRDBBlockGameObject (System.String blockName, System.Int32[] textureTable, Boolean allowExitDoors, DungeonTypes dungeonType, Single monsterPower, Int32 monsterVariance, Int32 seed, DaggerfallWorkshop.DaggerfallRDBBlock cloneFrom, Boolean importEnemies) [0x00000] in <filename unknown>:0 
  at DaggerfallWorkshop.DaggerfallDungeon.LayoutDungeon (DaggerfallConnect.DFLocation& location, Boolean importEnemies) [0x00000] in <filename unknown>:0 
  at DaggerfallWorkshop.DaggerfallDungeon.SetDungeon (DFLocation location, Boolean importEnemies) [0x00000] in <filename unknown>:0 
  at DaggerfallWorkshop.Utility.GameObjectHelper.CreateDaggerfallDungeonGameObject (DFLocation location, UnityEngine.Transform parent, Boolean importEnemies) [0x00000] in <filename unknown>:0 
  at DaggerfallWorkshop.Game.PlayerEnterExit.StartDungeonInterior (DFLocation location, Boolean preferEnterMarker, Boolean importEnemies) [0x00000] in <filename unknown>:0 
  at DaggerfallWorkshop.Game.PlayerEnterExit+<Respawner>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0 
  at UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) [0x00000] in <filename unknown>:0
You can find here a dfmod to reproduce this issue as well as the prefab, obj and blend models that I used to create the door:
https://github.com/XJDHDR/xjdhdr-random-code/tree/master/Random%20stuff%20uploaded%20for%20sharing%20online/Daggerfall%20Unity%20door%20problem%20files%20for%20forum

The door model I'm replacing is the secret door you open to leave the starting area of Privateer's Hold. So you can reproduce this by either loading a save made in PH or starting a new game.

Is there something wrong with my model or did I just find a bug? Help will be greatly appreciated. Thanks!

Here are the complete contents of output_log.txt if it helps. The error above starts at line 2539:
https://pastebin.com/Lv1Jy8KS
Last edited by XJDHDR on Fri Jul 31, 2020 3:00 am, edited 1 time in total.

User avatar
BadLuckBurt
Posts: 948
Joined: Sun Nov 05, 2017 8:30 pm

Re: Black screen and NullReferenceException error by replacing door model

Post by BadLuckBurt »

A few things are off:

1. You have not applied the Scaling setting in Blender and instead left them at 0.025. You need to apply them so it returns to 1.0
2. For some reason, your prefab has position coordinates set. These should all be 0.0
3. Your model is also rotated 180 degrees around the Y-axis, should be 0.0

Image

4. What is the 'default' thing in the prefab? I don't get those when I use FBX

Image

I bet it's one of the objects in the prefab that's throwing the NullReferenceException.

Image
Image

For comparison, this is what my prefab looks like using an FBX:

Image

I don't know where you're going wrong exactly so it would help if you describe your process step by step. I exported your door from Blender to FBX, made a prefab through CreatePrefab, dragged the FBX model onto it and it ran perfectly fine in DFU. This door is the one in the throneroom, correct?
Last edited by BadLuckBurt on Mon Apr 20, 2020 12:58 pm, edited 1 time in total.
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

.

User avatar
MasonFace
Posts: 543
Joined: Tue Nov 27, 2018 7:28 pm
Location: Tennessee, USA
Contact:

Re: Black screen and NullReferenceException error by replacing door model

Post by MasonFace »

I think it's most likely that you're missing some components on your door prefab. According to the GitHub implementation details for adding action doors, it looks like you need to add the components that are on any other action door to your prefab that's holding the custom model. So inside the unity editor, find another door and see what components show up in the inspector for it. Make your prefab match that and see if it works.

If you are using any custom scripts on the prefab, make sure you add the [ImportedCompnent] attribute to the script so it loads in properly after serialization.

Also, from your output log it seems like you might be running mods. Try disabling them while you're working on this injection just to rule out any incompatibility first.


I hope this helps.

User avatar
BadLuckBurt
Posts: 948
Joined: Sun Nov 05, 2017 8:30 pm

Re: Black screen and NullReferenceException error by replacing door model

Post by BadLuckBurt »

MasonFace wrote: Mon Apr 20, 2020 12:43 pm I think it's most likely that you're missing some components on your door prefab. According to the GitHub implementation details for adding action doors, it looks like you need to add the components that are on any other action door to your prefab that's holding the custom model. So inside the unity editor, find another door and see what components show up in the inspector for it. Make your prefab match that and see if it works.

If you are using any custom scripts on the prefab, make sure you add the [ImportedCompnent] attribute to the script so it loads in properly after serialization.

Also, from your output log it seems like you might be running mods. Try disabling them while you're working on this injection just to rule out any incompatibility first.


I hope this helps.
He's not making a custom door, he's just replacing the model so he doesn't need any extra components. In fact, I think it's throwing an error because he has some components in there that shouldn't be. I exported his .blend to FBX and it worked fine when I made a prefab out of it.

Disabling mods is always a good idea although I don't think it would make a difference in this case.
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

.

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

Re: Black screen and NullReferenceException error by replacing door model

Post by TheLacus »

MasonFace is correct, read the commit message:

Added support for injection of custom models of action doors used inside buildings and dungeons. The entire action door prefab is replaced, so mod authors need to ensure that DaggerfallActionDoor, DaggerfallAudioSource and other required components (or compatible replacements) are present
This provides more flexibility for mod authors if they also want to change sounds or other functionalities.

Code: Select all

// Get action door script
DaggerfallActionDoor actionDoor = go.GetComponent<DaggerfallActionDoor>();

// Set starting lock value
byte[] lockValues = { 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x19, 0x1E, 0x32, 0x80, 0xFF };
actionDoor.StartingLockValue = lockValues[obj.Resources.ModelResource.TriggerFlag_StartingLock >> 4];

// Set LoadID
actionDoor.LoadID = loadID;
It's probably worth to add a check and log an error message here.

User avatar
MasonFace
Posts: 543
Joined: Tue Nov 27, 2018 7:28 pm
Location: Tennessee, USA
Contact:

Re: Black screen and NullReferenceException error by replacing door model

Post by MasonFace »

I think it's throwing an error because he has some components in there that shouldn't be. I exported his .blend to FBX and it worked fine when I made a prefab out of it.
That's intriguing. I don't know that I've ever encountered having extra components to throw a null reference exception before, but you're definitely right that those extra components and gameobjects didn't need to be in the imported prefab.

And yours worked without adding the DaggerfallAudioSource, DaggerfallActionDoor, etc.? Did you package a .dfmod file or are you running a virtual mod? Don't know if there might be a difference in this case; I'm just trying to rationalize how yours is working without adding the required components.

User avatar
BadLuckBurt
Posts: 948
Joined: Sun Nov 05, 2017 8:30 pm

Re: Black screen and NullReferenceException error by replacing door model

Post by BadLuckBurt »

MasonFace wrote: Mon Apr 20, 2020 1:20 pm
I think it's throwing an error because he has some components in there that shouldn't be. I exported his .blend to FBX and it worked fine when I made a prefab out of it.
That's intriguing. I don't know that I've ever encountered having extra components to throw a null reference exception before.
And yours worked without adding the DaggerfallAudioSource, DaggerfallActionDoor, etc. ? Either way, you're definitely right that those extra components and gameobjects didn't need to be in the imported prefab.

Did you package a .dfmod file or are you running a virtual mod? Don't know if there might be a difference in this case; I'm just trying to rationalize how yours is working without adding the required components.
I'm just a massive dork, I forgot to add the dfmod I made to the Mods folder. I get the black screen like he did, going to add the components now and retry.

- edit

Added the DaggerfallActionDoor and DaggerfallAudioSource components and the black screen is gone. Door position is off but that's because I didn't reset the origin in Blender. It does open and close like it's supposed to.

Closed :D
Image

Opened :lol:
Image
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

.

User avatar
MasonFace
Posts: 543
Joined: Tue Nov 27, 2018 7:28 pm
Location: Tennessee, USA
Contact:

Re: Black screen and NullReferenceException error by replacing door model

Post by MasonFace »

Sounds like you've got the issue pretty much resolved now. I'm excited to see what XJDHDR is planning to do with this! :P

User avatar
XJDHDR
Posts: 258
Joined: Thu Jan 10, 2019 5:15 pm
Location: New Zealand
Contact:

Re: Black screen and NullReferenceException error by replacing door model

Post by XJDHDR »

Thanks for the help everyone. I have my door working now and the problem was that that I didn't know about adding the DaggerfallActionDoor and DaggerfallAudioSource scripts. I didn't think that I needed to look through the commit history for this info.
BadLuckBurt wrote: Mon Apr 20, 2020 8:08 am 1. You have not applied the Scaling setting in Blender and instead left them at 0.025. You need to apply them so it returns to 1.0
I've found that exporting the model as-is from Blender then adjusting the scale in Unity suits my workflow more.
BadLuckBurt wrote: Mon Apr 20, 2020 8:08 am 2. For some reason, your prefab has position coordinates set. These should all be 0.0
3. Your model is also rotated 180 degrees around the Y-axis, should be 0.0
The positions are there because I created the prefab by dragging the model into the scene then dragging the new prefab from the hierarchy into the project explorer. It's rotated because I've found that every model I export from Blender is rotated 180° the wrong way. I could try fix the rotation in Blender but I was trying to stick to exporting as-is then tweaking in Unity. These 6 numbers don't really matter for just replacing existing models because I think DFU overrides them when it is placing them in the scene at runtime. Changing them hasn't had any effect on the models I've replaced so far.
BadLuckBurt wrote: Mon Apr 20, 2020 8:08 am 4. What is the 'default' thing in the prefab? I don't get those when I use FBX
It's just the way Unity handles OBJ models as far as I can tell. I think that 'default' thing is the mesh itself.
BadLuckBurt wrote: Mon Apr 20, 2020 8:08 am This door is the one in the throneroom, correct?
The one I'm thinking of is the secret door that you open while leaving the starting cave area and enter that first room with the rat in it.
MasonFace wrote: Mon Apr 20, 2020 12:43 pm I think it's most likely that you're missing some components on your door prefab. According to the GitHub implementation details for adding action doors, it looks like you need to add the components that are on any other action door to your prefab that's holding the custom model.
TheLacus wrote: Mon Apr 20, 2020 1:16 pm MasonFace is correct, read the commit message:
Added support for injection of custom models of action doors used inside buildings and dungeons. The entire action door prefab is replaced, so mod authors need to ensure that DaggerfallActionDoor, DaggerfallAudioSource and other required components (or compatible replacements) are present
This provides more flexibility for mod authors if they also want to change sounds or other functionalities.
How can I find out what components were attached to the original door that I'm replacing? Looking around, I see that there are 4 door related prefabs under Prefabs\Scene. Am I correct in assuming that all the vanilla doors in DFU use one of these 4 prefabs?
MasonFace wrote: Mon Apr 20, 2020 1:40 pm I'm excited to see what XJDHDR is planning to do with this! :P
I don't personally consider my project too exciting. I'm just fixing some bugs. I do want to release it but I'm waiting for a modding feature that TheLacus recently added to be available in a release version of DFU.

User avatar
BadLuckBurt
Posts: 948
Joined: Sun Nov 05, 2017 8:30 pm

Re: Black screen and NullReferenceException error by replacing door model

Post by BadLuckBurt »

Glad you got it to work, I didn't know about those components myself, I knew something similar was needed for static doors that triggers an interior / exterior transition but wasn't aware the action doors needed components added.
XJDHDR wrote: Tue Apr 21, 2020 9:36 am I've found that exporting the model as-is from Blender then adjusting the scale in Unity suits my workflow more.
Bad practice in my opinion but your choice.
XJDHDR wrote: Tue Apr 21, 2020 9:36 am The positions are there because I created the prefab by dragging the model into the scene then dragging the new prefab from the hierarchy into the project explorer. It's rotated because I've found that every model I export from Blender is rotated 180° the wrong way. I could try fix the rotation in Blender but I was trying to stick to exporting as-is then tweaking in Unity. These 6 numbers don't really matter for just replacing existing models because I think DFU overrides them when it is placing them in the scene at runtime. Changing them hasn't had any effect on the models I've replaced so far.
All that's needed in Blender is to rotate 180 degrees around the Z-axis and then applying the rotation before exporting. Won't matter for individual models as much as it does for entire layouts which is where I ran into problems. The reason for incorrect rotation is that Unity uses a left-hand coordinate system and Blender uses a right-handed one.
XJDHDR wrote: Tue Apr 21, 2020 9:36 am It's just the way Unity handles OBJ models as far as I can tell. I think that 'default' thing is the mesh itself.
Alright. I find FBX to be a lot cleaner than OBJ but whatever works for you.
XJDHDR wrote: Tue Apr 21, 2020 9:36 am The one I'm thinking of is the secret door that you open while leaving the starting cave area and enter that first room with the rat in it.
Cool, it's the same model.
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

.

Post Reply