Search Unity

Anyone else wish that Vector3 implemented IFormattable?

Discussion in 'Scripting' started by Kylotan, May 31, 2019.

  1. Kylotan

    Kylotan

    Joined:
    Feb 17, 2011
    Posts:
    212
    Often I log Vector3s and the default is 1 decimal place - usually not enough for debugging. It's possible to work around that with a .ToString("F3") call or similar. But what would be even better is if I could just use it in a format string like so: $"my vector is {myVector:F3}". But since Vector3 doesn't implement IFormattable, this doesn't work. Same goes for Debug.LogFormat - since it appears to just call through to string.Format and that checks for IFormattable on the type in question, it can't process the F3 format specifier automatically.

    Anyone else wish this could be fixed?
     
  2. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Unity.Mathematics types do implement it, and there is implicit casting between those and UnityEngine types, so that's one option.