googlevr / tilt-brush-toolkit

Scripts and assets that help you use Tilt Brush data in your creative projects.
Apache License 2.0
744 stars 164 forks source link

Tilt Brush Fbx Import Null Reference Error #48

Closed vrimages closed 4 years ago

vrimages commented 4 years ago

Hello,

I'm using TiltBrushToolkit with Unity 2019.3.7f1. Whenever I import an fbx file that I exported from Tilt Brush, I get a bunch of lines in the Console with the error:

"NullReferenceException: Object reference not set to an instance of an object TiltBrushToolkit.ModelImportSettings.GetDescriptorForStroke (System.String oldMaterialName) (at Assets/tilt-brush-toolkit/UnitySDK/Assets/TiltBrush/Scripts/Editor/ModelImportSettings.cs:440) TiltBrushToolkit.ModelImportSettings.OnAssignMaterialModel (UnityEngine.Material material, UnityEngine.Renderer renderer) (at Assets/tilt-brush-toolkit/UnitySDK/Assets/TiltBrush/Scripts/Editor/ModelImportSettings.cs:218) System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <437ba245d8404784b9fbab9b439ac908>:0) Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation."

Any thoughts on how to fix this?

Line 440 of ModelImportSettings.cs is: return TbtSettings.BrushManifest.BrushesByGuid[brushGuid];

Line 218 of ModelImportSettings.cs is: BrushDescriptor desc = GetDescriptorForStroke(material.name);

Thank you!

ky3u commented 4 years ago

Odd, I'm using 2018.4.20f1 and am not having those console errors.

dubois commented 4 years ago

Both TbtSettings and BrushManifest are .asset files that come with the Tilt Brush Toolkit. It sounds like maybe the link from the TbtSettings -> BrushManifest asset has been broken. Check it out in the inspector. For example, search for t:TbtSettings in your project pane. View the asset in the inspector (there should be only one) and make sure m_BrushManifest points at the one file of t:BrushManifest in your project.

vrimages commented 4 years ago

Hi @dubois , thanks for the tip. It would be strange if that link is broken, since I simply imported the toolkit that seems to be working seamlessly for others. I looked through the code and various Inspector settings and couldn't find anything amiss.

I ended up reimporting my Tilt Brush sketch's .fbx file after reimporting the Tilt Brush Toolkit (this time I only imported the "UnitySDK" folder instead of cloning the whole repository to my Assets folder), and the aforementioned error went away.

However, now I'm getting this error: "Shader error in 'Brush/Special/Electricity': failed to open source file: 'Assets/ThirdParty/Noise/Shaders/Noise.cginc' at line 26 (on d3d11)"

And some of my brush stroke's materials (for the Ink, Oil Paint, and Thick Paint brushes) aren't matching up (they're just the default unlit material, while other brushes are matching up accurately).

Any tips on fixing this?

Thank you.

dubois commented 4 years ago

Hm. Well, my first tip is not to clone the repository to your Assets folder. Instead, use a .unitypackage that you can find on the "releases" page of this repo.

Your unexpected file layout is what's breaking your shader. I don't know what's causing those other materials to be broken, but likely it's a similar issue.

vrimages commented 4 years ago

Ah, haha looks like I forgot to follow the directions. Deleting the UnitySDK folder and importing the package cleared up all the console errors.

Re importing the .fbx export from Tilt Brush resulted in a beautiful, color-matched prefab.

Thank you, @dubois!