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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Create UnityPlayer instance with non activity context

Discussion in 'Android' started by zoranigic, May 27, 2021.

  1. zoranigic

    zoranigic

    Joined:
    Oct 4, 2019
    Posts:
    16
    When I try to create instance of UnityPlayer in native android, passing context that is not activity:

    mUnityPlayer = new UnityPlayer(getContext());

    e.g. application context, my app crash with following stack trace:

    2021-05-27 15:40:09.776 2276-2328/com.DefaultCompany.LW2WithOlderUnityVersion A/zygote64: java_vm_ext.cc:534] JNI DETECTED ERROR IN APPLICATION: can't call android.view.WindowManager android.app.Activity.getWindowManager() on null object
    2021-05-27 15:40:09.776 2276-2328/com.DefaultCompany.LW2WithOlderUnityVersion A/zygote64: java_vm_ext.cc:534] in call to CallObjectMethodV
    2021-05-27 15:40:09.776 2276-2328/com.DefaultCompany.LW2WithOlderUnityVersion A/zygote64: java_vm_ext.cc:534] from boolean com.unity3d.player.UnityPlayer.nativeRender()......

    Question is what am I doing wrong?
    Can UnityPlayer be created with context that is not activity?
    Thanks!
     
    Last edited: May 28, 2021
    tigerss likes this.
  2. unity_2E90A32BB809D3CEF993

    unity_2E90A32BB809D3CEF993

    Joined:
    Jan 20, 2022
    Posts:
    5
    hi, did you solve the problem? I have the same error!:(
     
  3. yakkalajayaram

    yakkalajayaram

    Joined:
    Nov 17, 2020
    Posts:
    4
    Any update on this issue?
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,652
    We've stopped supporting this due to very low interest in it.
     
  5. unity_2E90A32BB809D3CEF993

    unity_2E90A32BB809D3CEF993

    Joined:
    Jan 20, 2022
    Posts:
    5
    Hi, do you mean UnityPlayer cannot be created with non Activity (such as Service) context anymore? Do you know any method to support it or which unity version support this? :(
     
  6. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    In Unity 2022.1 UnityPlayer constructor has an Activity parameter. Unity 2020LTS and 2021.2 still has a Context parameter, however UnityPlayer code assumes it received an Activity. If you are using a Unity version which works with other types of contexts, then that most likely is a lucky accident, since on our side only an Activity Context is tested.
    I'm curious, which Unity version are you using currently?
     
  7. unity_2E90A32BB809D3CEF993

    unity_2E90A32BB809D3CEF993

    Joined:
    Jan 20, 2022
    Posts:
    5
    :(:(:(
    I am learning to make live wallpaper for Android using the Android WallpaperService and Unity 2021. I googled the tutorials and tried, then the same error in this post happened.
    Someone says Unity2018 can work well. So why the latest Unity version stops supporting non-activity context? Is there any solution to make live wallpaper with latest Unity? It confuses me a long time. Please help me
     
  8. EuanHollidge

    EuanHollidge

    Joined:
    Nov 3, 2014
    Posts:
    69
    Hi, I currently am selling an asset based on this feature. Does this mean I must retire the asset?
     
  9. unity_2E90A32BB809D3CEF993

    unity_2E90A32BB809D3CEF993

    Joined:
    Jan 20, 2022
    Posts:
    5
    I think the answer is yes. Is your asset for making wallpaper?
     
  10. EuanHollidge

    EuanHollidge

    Joined:
    Nov 3, 2014
    Posts:
    69
    Yes, it does. I think unfortunately you're probably correct.

    Can you give a definitive response to whether or not this is true?
     
    tigerss likes this.
  11. unity_2E90A32BB809D3CEF993

    unity_2E90A32BB809D3CEF993

    Joined:
    Jan 20, 2022
    Posts:
    5
    is there any further update?