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
4
Question by vexe · Nov 10, 2013 at 04:59 PM · c#consolelogdebug.log

Is there a logging method, similar to C#'s Console.WriteLine? (what I want is the {N})

Hello guys,

I was just testing something when I accidentally wrote:

 Debug.Log("There are {0} elements in my list", list.Count);

Then I remembered I can't do that in Debug.Log - And I can't use Console.WriteLine to output to Unity's console (can I?)

Is there a way of doing this? Does Unity have a logging method, that supports this? or do I have to try to implement this thing myself? - Not that it's not doable, but won't be too easy.

Thanks.

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

3 Replies

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

Answer by phxvyper · Nov 10, 2013 at 05:53 PM

The {N} function used in Console.WriteLine is the same exact thing used in String.Format.

For example:

 Debug.Log(String.Format("Hello {0}, you are {1} years old.", name, age));


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
6

Answer by Eric5h5 · Nov 10, 2013 at 05:53 PM

Use System.String.Format.

 Debug.Log (String.Format("There are {0} elements in my list", list.Count));
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
2

Answer by tw1st3d · Nov 10, 2013 at 05:47 PM

 Debug.Log("There are " + list.Count + " elements in my list");
Comment
Add comment · Show 3 · 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 vexe · Nov 10, 2013 at 05:55 PM 1
Share

Thanks for your reply ^^ - I know about that of course. But in WriteLine you could do stuff like:

 Console.WriteLine("Hello, my name is {0}, I'm {1} years old, and I like {2}", name, age, hobby);

Very neat, very elegant, cleaner and easier to write!

As apposed to:

 Debug.Log("Hello, my name is " + name + " I'm " + age + " years old, and I like " + hobby);

I hope you're feeling me now...

avatar image tw1st3d · Nov 10, 2013 at 05:58 PM 0
Share

I feel like you may be talking about C#'s formatting system, in which case this answer holds no merit. However, there's another solution which may help (that I can't describe perfectly), but it's using % to parse what's being called.

It's something like

 Debug.Log('%s%n%s', "There are ", list.Count, " elements in my list");

I may be off on what the letters are, but I was just going with %s = string, %n = number. %n isn't right, but I don't know what's supposed to be there, as I find this method of printing extremely useless.

avatar image vexe · Nov 11, 2013 at 06:37 AM 0
Share

Don't know about this. I'll check it out. This does seem like C, good old days :)

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

19 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Can I display the console ouput on the 3D object?,Can I display output from the console on the 3D object? 1 Answer

Debug log to website. 2 Answers

How do I change the default application used to open logs from the Unity editor? (on Mac) 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