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 Xerosigma · Jun 09, 2012 at 10:22 PM · c#arraydebug.logmultidimensional array

C# Debug 3D Array

I have a three dimensional array: Dictionary m_data = new Dictionary ();

Here, I try to debug the dictionary:

 foreach(KeyValuePair<Vector3i,int[,,]> data in m_data)
             {
                 Debug.Log("Section: " + data.Key + " | Unit: " + data.Value);
             }

Of course only data.Key displays as expected. How can I debug all the elements of data.Value here as well?

Thanks in advance.

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 Jessy · Jun 09, 2012 at 11:14 PM 0
Share

Using "data" and "m_data" is not good practice. The singular form of data is datum. Also, learn the var keyword!

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Jun 09, 2012 at 11:26 PM

How do you want the 3D array to be displayed? There's no way around iterating through all elements. A 3D array is difficult to view in a reasonable way. One would be to treat it like it was a jagged array, so you have 3 nested arrays. Something like that:

 [[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]

this is not very helpful if there are many values since the structure is really hard to read.

What data is stores in the array? And how many elements per dimension do you have? Just to clarifiy, my example above has an element counr of 2, 2, 3 which is not that much.

A function that forms a string like that could look like this:

 // C#
 string Format3DArray(int[,,] array)
 {
     string result = "";
     for(int d0 = 0; d0 < array.GetLength(0);d0++)
     {
         if (d0>0) result += ",";
         result += "[";
         for(int d1 = 0; d1 < array.GetLength(1);d1++)
         {
             if (d1>0) result += ",";
             result += "[";
             for(int d2 = 0; d2 < array.GetLength(2);d2++)
             {
                 if (d2>0) result += ",";
                 result += array[d0,d1,d2].ToString();
             }
             result += "]";
         }
         result += "]";
     }
     result += "]";
     return result;
 }

Usually it's better to use a StringBuilder for this, but since it's just for debugging i don't care about performance ;)

ps. i just wrote that from scratch so forgive any potential typing / syntax errors ;)

edit
You can also use MonoDevelop to debug your game and insert a breakpoint so you can inspect the variables directly. Never used multidim arrays when i was debugging, so i don't know how MonoDevelop will display such an array.

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

Answer by Datael · Jun 09, 2012 at 10:41 PM

I may be misunderstanding you but it looks like you need to override ToString() in your Vector3i object.

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 Xerosigma · Jun 09, 2012 at 11:05 PM 0
Share

The data.$$anonymous$$ey is the only element that is currently typed as Vector3i, and it's printing correctly. It's data.Value, which is an int[,,], that I'm trying to debug.

avatar image Datael · Jun 09, 2012 at 11:34 PM 0
Share

Ho ho it certainly does! Reading the question again it was certainly a terrible answer. $$anonymous$$y apologies.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Are multidimensional arrays supported in UNET? 1 Answer

2D array initialized but send Null 1 Answer

Trying to Sort a Multi Dimensional Array 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers


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