glTFast icon indicating copy to clipboard operation
glTFast copied to clipboard

Unable to import a .glb file on Android

Open Creepymulder opened this issue 1 year ago • 20 comments

Describe the bug

Hello there!

I'm trying to import a .glb file using the "Gltf asset" script with all option on default. No custom code.

It's working fine on the editor, but on Android I'm getting the following :

2023/02/27 17:16:43.283 19335 19365 Error Unity NullReferenceException: Object reference not set to an instance of an object. 2023/02/27 17:16:43.283 19335 19365 Error Unity at GLTFast.Materials.BuiltInMaterialGenerator.GenerateDefaultMaterial (System.Boolean pointsSupport) [0x00000] in <00000000000000000000000000000000>:0 2023/02/27 17:16:43.283 19335 19365 Error Unity at GLTFast.Materials.MaterialGenerator.GetDefaultMaterial (System.Boolean pointsSupport) [0x00000] in <00000000000000000000000000000000>:0 2023/02/27 17:16:43.283 19335 19365 Error Unity at GLTFast.GameObjectInstantiator.AddPrimitive (System.UInt32 nodeIndex, System.String meshName, UnityEngine.Mesh mesh, System.Int32[] materialIndices, System.UInt32[] joints, System.Nullable1[T] rootJoint, System.Single[] morphTargetWeights, System.Int32 primitiveNumeration) [0x00000] in <00000000000000000000000000000000>:0 2023/02/27 17:16:43.283 19335 19365 Error Unity at GLTFast.GltfImport+<>c__DisplayClass116_0.<InstantiateSceneInternal>g__PopulateHierarchy|2 (System.UInt32 nodeIndex, System.Nullable1[T] parentIndex) [0x00000] in <00000000000000000000000000000000>:0 2023/02/27 17:16:43.283 19335 19365 Error Unity at GLTFast.GltfImport+<>c__DisplayClass116_0.<InstantiateSceneInternal>g__IterateNodes|0 (System.UInt32 nodeI

The .GLB file in question is attached.

Unity 2022.2.2f1 Galaxy Tab S7 with Android 13

haha-63f797eb227eb(2).zip

I've also tried all the manual way to import a .GLB following the documentation, but they all end with the same error message.

Thanks !

Creepymulder avatar Feb 28 '23 16:02 Creepymulder

@Creepymulder Try this #580

amrmohamed25 avatar Mar 12 '23 18:03 amrmohamed25

Similar issue here, the normal loading script works on Desktop builds and Editor on Windows 11 and M1 Mac, works fine on device on IOS. On Android if we try to load a file that has a mesh, materials and textures in it, I get

16028 16053 Error CRASH Cause: null pointer dereference

Interestingly, files that contain only animated bones in them with no materials or textures load fine, this includes an animation only file that I am using to retarget an animation to a model already in the scene.

ROBYER1 avatar Mar 21 '23 14:03 ROBYER1

Any update on this? I need to make this work for android for my bachelor thesis... I'm running into the exact same error which throws me back in my timeplan.

genaray avatar May 02 '23 13:05 genaray

Any update on this? I need to make this work for android for my bachelor thesis... I'm running into the exact same error which throws me back in my timeplan.

I believe this issue is actually this issue I found later on, on Android we could only load glb/gltf that used KTX2 textures. Jpeg/Png don't work. https://github.com/atteneder/glTFast/issues/590

ROBYER1 avatar May 02 '23 14:05 ROBYER1

Any update on this? I need to make this work for android for my bachelor thesis... I'm running into the exact same error which throws me back in my timeplan.

I believe this issue is actually this issue I found later on, on Android we could only load glb/gltf that used KTX2 textures. Jpeg/Png don't work. #590

Thanks for the fast answer! Will this be fixed in the near future? Or this even fixable?

Would you recommend Gltfunity for this particular case instead?

genaray avatar May 02 '23 14:05 genaray

Any update on this? I need to make this work for android for my bachelor thesis... I'm running into the exact same error which throws me back in my timeplan.

Did you try #580?

amrmohamed25 avatar May 02 '23 14:05 amrmohamed25

Any update on this? I need to make this work for android for my bachelor thesis... I'm running into the exact same error which throws me back in my timeplan.

Did you try #580?

Do you think this could make it work? I can not change the model directly however... Im gonna give it a try, lets see if it works.

genaray avatar May 02 '23 14:05 genaray

Any update on this? I need to make this work for android for my bachelor thesis... I'm running into the exact same error which throws me back in my timeplan.

Did you try #580?

Do you think this could make it work? I can not change the model directly however... Im gonna give it a try, lets see if it works.

I guess it will but can tell me what are you expecting? In my case i was expecting to display a glb model that is stored on a server with all textures on it and it worked for all models that i used. Note: i didnt try to use URP

amrmohamed25 avatar May 02 '23 14:05 amrmohamed25

I guess it will but can tell me what are you expecting?

Well, like mentioned in the issue. Theres a glb file stored on a server with textures and materials on it and i wanna load it during runtime on android devices. Its actually a crucial part for my bachelor thesis. Im not using URP either, still on the inbuild renderpipeline. However i receive exact the same issue as described above.

The glb file I'm using (from sketchfab) : https://sketchfab.com/3d-models/coffee-maker-9ccda2fddba846e6ba97eb774b8a09c6

genaray avatar May 02 '23 14:05 genaray

I guess it will but can tell me what are you expecting?

Well, like mentioned in the issue. Theres a glb file stored on a server with textures and materials on it and i wanna load it during runtime on android devices. Its actually a crucial part for my bachelor thesis. Im not using URP either, still on the inbuild renderpipeline. However i receive exact the same issue as described above.

The glb file I'm using (from sketchfab) : https://sketchfab.com/3d-models/coffee-maker-9ccda2fddba846e6ba97eb774b8a09c6

I guess it will work with all that mentioned

amrmohamed25 avatar May 02 '23 14:05 amrmohamed25

I guess it will but can tell me what are you expecting?

Well, like mentioned in the issue. Theres a glb file stored on a server with textures and materials on it and i wanna load it during runtime on android devices. Its actually a crucial part for my bachelor thesis. Im not using URP either, still on the inbuild renderpipeline. However i receive exact the same issue as described above. The glb file I'm using (from sketchfab) : https://sketchfab.com/3d-models/coffee-maker-9ccda2fddba846e6ba97eb774b8a09c6

I guess it will work with all that mentioned

It really worked thanks! :) Well it works partially... The model shows up, but its all black for some reason. I downloaded and included the shaders as you said, i put them into Assets/Resources/Shaders (since you haven't mentioned a particular folder). One think i have noticed is that one of the shaders throws errors at me: https://prnt.sc/iVSFuSSR1r28

image

Any clue why its all black? And why that one shader throws those errors?

genaray avatar May 02 '23 14:05 genaray

I guess it will but can tell me what are you expecting?

Well, like mentioned in the issue. Theres a glb file stored on a server with textures and materials on it and i wanna load it during runtime on android devices. Its actually a crucial part for my bachelor thesis. Im not using URP either, still on the inbuild renderpipeline. However i receive exact the same issue as described above. The glb file I'm using (from sketchfab) : https://sketchfab.com/3d-models/coffee-maker-9ccda2fddba846e6ba97eb774b8a09c6

I guess it will work with all that mentioned

It really worked thanks! :) Well it works partially... The model shows up, but its all black for some reason. I downloaded and included the shaders as you said, i put them into Assets/Resources/Shaders (since you haven't mentioned a particular folder). One think i have noticed is that one of the shaders throws errors at me: https://prnt.sc/iVSFuSSR1r28

Any clue why its all black? And why that one shader throws those errors?

Did you include the pbrMetallicRoughness in the Always included shaders?

amrmohamed25 avatar May 02 '23 14:05 amrmohamed25

Did you include the pbrMetallicRoughness in the Always included shaders?

Yes i have, like this : (Thats the correct one, right?) image

However that one throws those errors at me: image

Any ideas?

genaray avatar May 02 '23 14:05 genaray

Did you include the pbrMetallicRoughness in the Always included shaders?

Yes i have, like this : (Thats the correct one, right?) image

However that one throws those errors at me: image

Any ideas?

It's correct. Can you replace it with the one inside the glTFast itself it is located in glTFast directory / Runtime/shader/Built-in

amrmohamed25 avatar May 02 '23 14:05 amrmohamed25

Can you replace it with the one inside the glTFast itself it is located in glTFast directory / Runtime/shader/Built-in

What exactly do you mean? Like replacing the pbrMetallicRoughness shader? I actually downloaded it from https://github.com/atteneder/glTFast/blob/main/Runtime/Shader/Built-In/glTFPbrMetallicRoughness.shader which should be sufficient. Or do you mean something else?

I think the metallicroughness shader itself is not the problem, its the included that are missing. However i have no idea on how to add them to make that work properly.

genaray avatar May 02 '23 14:05 genaray

Can you replace it with the one inside the glTFast itself it is located in glTFast directory / Runtime/shader/Built-in

What exactly do you mean? Like replacing the pbrMetallicRoughness shader? I actually downloaded it from https://github.com/atteneder/glTFast/blob/main/Runtime/Shader/Built-In/glTFPbrMetallicRoughness.shader which should be sufficient. Or do you mean something else?

I think the metallicroughness shader itself is not the problem, its the included that are missing. However i have no idea on how to add them to make that work properly.

It should be sufficient but i dont have any of these errors so you could try to replace the pbrMetallicRoughness.shader that is in the Always Included Shaders with the one that is inside the package directory in your project inside the / Runtime/shader/Built-in If that didnt work you could try including these shaders also but in my case i didnt have to

amrmohamed25 avatar May 02 '23 14:05 amrmohamed25

Can you replace it with the one inside the glTFast itself it is located in glTFast directory / Runtime/shader/Built-in

What exactly do you mean? Like replacing the pbrMetallicRoughness shader? I actually downloaded it from https://github.com/atteneder/glTFast/blob/main/Runtime/Shader/Built-In/glTFPbrMetallicRoughness.shader which should be sufficient. Or do you mean something else? I think the metallicroughness shader itself is not the problem, its the included that are missing. However i have no idea on how to add them to make that work properly.

It should be sufficient but i dont have any of these errors so you could try to replace the pbrMetallicRoughness.shader that is in the Always Included Shaders with the one that is inside the package directory in your project inside the / Runtime/shader/Built-in If that didnt work you could try including these shaders also but in my case i didnt have to

Solved it, now works. I included the whole folder where those missing included were located at and dropped in the shader with meta data again. Thanks!

genaray avatar May 02 '23 15:05 genaray

Can you replace it with the one inside the glTFast itself it is located in glTFast directory / Runtime/shader/Built-in

What exactly do you mean? Like replacing the pbrMetallicRoughness shader? I actually downloaded it from https://github.com/atteneder/glTFast/blob/main/Runtime/Shader/Built-In/glTFPbrMetallicRoughness.shader which should be sufficient. Or do you mean something else? I think the metallicroughness shader itself is not the problem, its the included that are missing. However i have no idea on how to add them to make that work properly.

It should be sufficient but i dont have any of these errors so you could try to replace the pbrMetallicRoughness.shader that is in the Always Included Shaders with the one that is inside the package directory in your project inside the / Runtime/shader/Built-in If that didnt work you could try including these shaders also but in my case i didnt have to

Solved it, now works. I included the whole folder where those missing included were located at and dropped in the shader with meta data again. Thanks!

That's great. Happy to hear that. Good luck finishing your bachelor thesis

amrmohamed25 avatar May 02 '23 15:05 amrmohamed25

Sorry I haven't been able to test it out since I created this issue, but I'm glad it's working with this fix, thanks a lot :-).

Creepymulder avatar May 02 '23 15:05 Creepymulder

Sorry I haven't been able to test it out since I created this issue, but I'm glad it's working with this fix, thanks a lot :-).

No problem at all. you are welcome :)

amrmohamed25 avatar May 02 '23 15:05 amrmohamed25