• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jackpoz · Jul 09, 2010 at 02:49 PM · arrayiphonelistexceptionmono

Using List.Count on Unity iPhone

this is a little piece of code that works like a charm in the Unity iPhone Editor but doesn't work on the iPhone, throwing an exception in the XCode console at runtime.

GameObject[] gos = GameObject.FindGameObjectsWithTag("TagUsedIngame");
//gos size is 4 in my test
List<GameObject> gosList = new List<GameObject>(gos);//<-- exception

the exception is documented at http://monotouch.net/Documentation/Troubleshoot

System.ExecutionEngineException: Attempting to JIT compile method (wrapper managed-to-managed) Foo[]:System.Collections.Generic.ICollection`1.get_Count () they suggest to write something like

Foo [] array = null;  
int count = ((ICollection<Foo>) array).Count;

which is pretty funny since this code will throw a null deref exception^^

did anyone already solve this issue? It's more related to Mono than to Unity, because it works fine in the Editor. I set .NET in the Player Settings of the Project to 2.1 . Thank you for the time spent reading this wall of text.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Dec 26, 2011 at 11:54 PM 0
Share

FYI Note this $$anonymous$$UCH NEWER answer from 2011

http://answers.unity3d.com/questions/54841/does-current-iphone-support-listt-in-c.html

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Molix · Jul 09, 2010 at 03:03 PM

I believe generics (System.Collections.Generic) are not fully supported on iPhone.

There are some good suggestions and details in this Q&A

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jackpoz · Jul 09, 2010 at 03:20 PM 0
Share

more like they are not supported at all, if i can't even get the Count of elements...

avatar image Jackpoz · Jul 09, 2010 at 03:48 PM 0
Share

indeed, had to use an ArrayList....

avatar image
1

Answer by Tetrad · Jul 09, 2010 at 04:02 PM

Don't construct a List with an array, it crashes on the phone. Known bug.

Instead add the objects one at a time.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jackpoz · Jul 11, 2010 at 09:51 AM 1
Share

i hackfixed it using the non-generic ArrayList type. ArrayList gos = new ArrayList(GameObject.FindGameObjectsWithTag(tag));

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

A node in a childnode? 1 Answer

Why does List.ToArray throw ArgumentException? 1 Answer

Using lists or arrays of transforms in Boo. 1 Answer

How to save and load a list (containing string data) with playerpref ? 1 Answer

Best way to list all active quests in a GUI 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges