1

im stuck on this one, i just want to load images through path string. The image loading isnt the problem here the problem is that i dont know why both variables are the same but just one 'exists'.

I used to open a folder to select the image but i changed my mind and just wanted the path input through InputField. Like "C:\Users\NAME\Images\bunnys.png" (idk)

And then it went weird..

for example i got my string variable called "imagePath" which is connected with my InputField. on the other side i got a string variable called "imagePath2" which gets the path through "EditorUtillity.OpenFilePanel"

using EditorUnity;


    imagePath2 = EditorUtility.OpenFilePanel("Explorer", "", "png");

If i printing out both variables after input. I get 1:1 the same values I:/Images/finish.png | I:/Images/finish.png on the left is "imagePath" and on the right is "imagePath2"

So i checked if these paths (which are the same paths) exists

    if(File.Exists(imagePath)){
       Debug.Log("imagePath does exist");
    }
    if(File.Exists(imagePath2)){
       Debug.Log("imagePath2 does exist");
    }

for some reason "imagePath" does not exists while "imagePath2" does. But WHY?!

andAnother1
  • 106
  • 9
  • 4
    I suggest you to compare two strings by program, not by your eyes, because not all the characters are printable. – shingo Apr 28 '22 at 15:23
  • 2
    Fast way to check for hidden characters is to compare the lengths. – Chuck Apr 28 '22 at 15:57
  • How do you get „imagePath“ ? – JeanLuc Apr 28 '22 at 21:00
  • @shingo unfortunatly i could not find a good way to do so yet but i will in the future. – andAnother1 Apr 28 '22 at 23:09
  • @Chuck weirdly the lengths of my strings are really weird in my project like a string = "" and got length 20, and after i retryed it i got length 21 out of it. So i dont think i can trust the length value at the moment. Other example a string contained "I:/Images/img.png" got length value of 22 while its just 17 letters. – andAnother1 Apr 28 '22 at 23:11
  • @JeanLuc as said, its connected with an InputField (TextMeshPro variant) i can just type the path in there, at least its what i want to achive with it. – andAnother1 Apr 28 '22 at 23:11
  • You could try out a lot of the solutions here to debug why imagePath2 is invalid: https://stackoverflow.com/questions/6198392/check-whether-a-path-is-valid#6198473 – JeanLuc Apr 30 '22 at 12:42
  • öhm its fixed, but it was really weird. What i can say is that the TMPro output (string) got wrong values in it even if there wasnt printed in "Debug.Log" like they got mostly a much longer .length than it should have been – andAnother1 May 21 '22 at 17:44
  • but i am not able to tell why exactly it aint worked and how i managed it to work. Me and a friend tested out a lot and then it suprisingly started working – andAnother1 May 21 '22 at 17:45

0 Answers0