Unity and iOS: line inside an “if” always running, no matter the condition

I have been dealing with this odd issue for a couple of days and I am really out of ideas.

I am programming in Unity for iOS. Here is the troubled fragment of code:

if (!aux.IsDownloaded())

The really strange issue is that aux.DownloadItem() is always executed. It doesn’t matter if the condition is true or false. If the condition is true, it shouldn’t go inside the ‘if’, but it does! It just skip the first line (restoreTransaction) and run the second one (DownloadItem). If the condition is false, it just runs normally.

I have tried several things in order to discover something more:

  • If I comment the DownloadItem line, the debugger shows that it runs the restoreTransaction line no matter the value of the condition, but it is really running the DownloadItem, since the downloading takes place.
  • If I replace the restoreTransaction line with any other expression (in my case, 15 lines of Debug.Log(“ARGGG”)), it just skip all of them and run the DownloadItem line.
    I am really lost. I thought that it could be a data corruption, so I deleted the Library folder in my Unity project and cleared Monodevelop cache, but it keeps doing this weird thing.

I don’t know what else to try. Any ideas would be welcome, please just drop any guess no matter how stupid it sounds in your heads, since I am really out of ideas, and at least I would like to keep trying.

EDIT: After some more test, there is clearly a difference between what the device is running and what I am debugging in monodevelop. Maybe a an issue from Unity 3D generating the xCode project?

This is by far the weirdest thing I have ever found.

Kind regards,


Kind of what Meat wrote. When something that odd happens, it’s usually my fault. Does IsDownloaded do anything strange, for example, start the download, or run as a coroutine?

But, for fun, try a rewrite. Add a beginDownload flag before the if, so you pull the DownLoadItem call out of that if, and into a second one. In case it really is a buggy translation problem.