Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 George 10 · Mar 27, 2011 at 04:14 PM · arrays

problem accesing arrays

Hello. here{s my problem.

I have two objects, ObjectA with scriptA and ObjectB with scriptB.

scriptA has the following.

var array1 =new int[5,9]; var array2 =new int[1];

function Start(){ array1[0,0] = 2; array2[0] = 3; }

and scriptB has the following

var value1 :int; var value2 :int;

function Start(){ value2=GameObject.Find("ObjectA").GetComponent("scriptA").array2[0]; value1=GameObject.Find("ObjectA").GetComponent("scriptA").array1[0,0]; }

value2 sets correctly at 3, but value1 gets the following error:

MissingFieldException: Field 'System.Int32[,].' not found.

What could be the problem?? thank you

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Eric5h5 · Mar 27, 2011 at 05:52 PM

It's better not to use strings with GetComponent (faster, plus you get compile-time errors instead of runtime errors), also using generics is a simple way to avoid dynamic typing, which for some reason causes problems with multi-dimensional arrays.

value2 = GetComponent.<ScriptA>().array2[0];
value1 = GetComponent.<ScriptA>().array1[0,0];
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 George 10 · Mar 27, 2011 at 06:00 PM 0
Share

Thanks a lot. this solved my problem, altough i didnt understand why it worked!

avatar image George 10 · Mar 27, 2011 at 06:01 PM 1
Share

Never$$anonymous$$d! now I understand! thanks for helping me!

avatar image
-1

Answer by Justin Warner · Mar 27, 2011 at 05:46 PM

Is value1 supposed to be accessing a 2D array? If so, it wouldn't be an int (Up top at the initializing), I believe. So I'd guess the problem is you're making value1 and int, but it can't be an int, because it's holding 2 values from the array.... If that makes sense.

Comment for further help.

Hope this makes sense, and good luck!

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 Eric5h5 · Mar 27, 2011 at 05:53 PM 0
Share

No, a single value from a multidimensional array is still an int; that's not the problem here.

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Get ParticleSystem (Shuriken) to play from array of game objects C# 2 Answers

How to find the index of an Object in an Array 2 Answers

Advance through array elements with math (++)? 1 Answer

Attempt at creating an array of text files results in different errors 1 Answer

2D Array keeps coming up as Null 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges