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

Prevent Xcode from removing an object as unused.

Discussion in 'Scripting' started by Uzair-Mahmood, Jul 8, 2017.

  1. Uzair-Mahmood

    Uzair-Mahmood

    Joined:
    Mar 21, 2015
    Posts:
    15
    I've recently started getting an issue with xcode removing one of my "gameObject" while unloading unused assets to reduce memory usage.

    The gameobject has a script on it which deals with my advertisement logic. The object is created only once on the startup and then it is used throughout the game by accessing its reference in other scripts. It also has "DontDestroyOnLoad" on it as well.
    I've been using the same logic in a lot of games but recently it has started giving me an issue. Every time a new scene is loaded, Xcode unloads a bunch of unused assets and it removes this gameObject along with it. When i try to reference it I get "nullReference" exception.

    I have placed logs to confirm that it is actually the xcode which is removing the object. I wanted to know if there is any way to stop Xcode from removing that gameObject.

    I have also tried checking "Dead Code Stripping" to "no" in BuildingSettings tab of Xcode but it doesn't help either as it doesn't let me build without it.

    Thank you for your help in advance.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,713
    Removal of game objects is done by the Unity engine, not XCode.

    XCode stripping occurs at compile time and is nothing related to this problem.

    Generally Unity will only unload a "Don'tDestroyOnLoad" object when you actually destroy it yourself with code.

    First of all make sure the object is truly being created properly on the iPhone device. It may work fine in the editor and fine in Android, and yet fail in iPhone, but this will have to do with the advertising library you're using, or something else, not with XCode.
     
    Kiwasi likes this.
  3. Uzair-Mahmood

    Uzair-Mahmood

    Joined:
    Mar 21, 2015
    Posts:
    15
    Thank you for the reply. I tried what i could see might be the issue but it didn't work so instead I created new scripts and distributed them on different object as a workaround and now its working.
     
  4. charmcrescini

    charmcrescini

    Joined:
    Sep 9, 2019
    Posts:
    18