Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resources.Load return null on some android devices

Discussion in 'Scripting' started by yusufdemir2012, Jul 7, 2021.

  1. yusufdemir2012

    yusufdemir2012

    Joined:
    Dec 21, 2013
    Posts:
    49
    Actually there is no error on unity editor and my devices. But I see some null referece exceptions for some devices on Firebase Crashlytics and Unity Cloud Diagnostics for Resources.Load. I am %100 sure about Resources.Load returning null because I added a few debugs like Debug.LogError(Resources.Load<blabla>("blabla") == null) and this code always returning true on devices that with problems.

    I am also I have Photon network sdk in my project and some users have null referece exceptions on PhotonNetwork.StaticReset. StaticReset method is trying to load resources and i think that's why the error is caused. (I can't see line numbers on Crashlytics and Unity Cloud Diagnostics because of I using IL2CPP script backend)

    It seems like the whole part of the codes containing Resources.Load returns null on these problematic devices.

    Any idea to fix this?

    Unity Version: 2020.3.1f1
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,713
    Are you seeing any exceptions in the
    adb logcat
    stream on those devices?
     
  3. yusufdemir2012

    yusufdemir2012

    Joined:
    Dec 21, 2013
    Posts:
    49
    Thanks for your reply. Actually I can't reach those devices. I just tracking unity exceptions from Crashlytics and Unity Cloud Diagnostics. I have six different android devices and those devices gives no exceptions unfortunately
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,713
    Of course! :)

    Is it a particularly large object, like a massive texture? Or an object that references large textures? Could be an out of memory error. Or else since you mention Photon, perhaps it is some weird networking exception, such as an SSL / certificate thing. Without seeing the log you could speculate endlessly...
     
    yusufdemir2012 likes this.
  5. yusufdemir2012

    yusufdemir2012

    Joined:
    Dec 21, 2013
    Posts:
    49
    My game is using OBB extension because of apk have large size. Maybe some users downloading apk from third party services without OBB data. Or when users downloading my app from play store, maybe some users could not download OBB. If this happening, can users reach Resources without OBB?
     
  6. VolodymyrBS

    VolodymyrBS

    Joined:
    May 15, 2019
    Posts:
    150
    No.
    Unity pack resources into OBB file.
    In short, when you split your binaries APK contains the first scene, scripts, java code, and native code. OBB contains resources, streaming assets, and other scenes

    Take a look https://docs.unity3d.com/Manual/android-OBBsupport.html
    section "How data is split between the APK and OBB" describes it
     
    yusufdemir2012 likes this.
  7. odysoftware

    odysoftware

    Joined:
    Jul 21, 2015
    Posts:
    84
    I have the exact same issue, and don't know how to resolve it - but i can see in crash reports that some people get null on Resources.Load - its only happening on Android and only a few (mostly pixel) devices...?
     
  8. yusufdemir2012

    yusufdemir2012

    Joined:
    Dec 21, 2013
    Posts:
    49
    I solved the problem by checking the OBB is exists in storage.

    For example; I have a Manager scriptable object in Resources folder. When game is started, firstly I am trying to load this scriptable object from resources folder by using Resources.Load function. If this function returning null, then it's mean the user is don't have OBB expansion file in storage. If this happening, then I'm showing the user a popup that the user doesn't have the OBB file and redirects him to the store
     
  9. odysoftware

    odysoftware

    Joined:
    Jul 21, 2015
    Posts:
    84
    Well I did not use obb, I used aab files with the automated splitting - so I think I have a completely different story then!

    What I have done now is removing the automated splitting (Play Asset Delivery) and managing the assetbundles myself again on Android - till now it seems to be resolved! I guess from the documentation they say that if you use aab files together with the automated PAD then you can only access streamingassets - so maybe Resources.Load worked fine, so I was never thinking that there could be a problem but not on a few special devices it causes issues...