❔ Loading a Unity Font object from an assembly's Embedded Resource
Well, I'm trying to load a font I have as a resource embedded in my C# assembly. I've tried a number of things, my most recent attempt seen here (ignore the bad variable names, I'll clean it up once I get it working):The idea being that once I successfully load the font, it will print something other than
0
. I have also tried passing the embedded "path" TextAdventure.Assets.unifont-15.0.06.otf
straight to the Font
constructor (both relative path & appended to the absolute path of the assembly). I have also put the .otf
file in a Unity Asset Bundle and used AssetBundle.LoadFromStream(fontStream).LoadAsset<Font>("assets/unifont-15.0.06.otf")
to try and grab the file.
Any ideas?16 Replies
well
if we want to approach this directly
new Font(file)
file
here is a string
which presumably should be a file path for the file containing the fontcorrect, it's a path
what it ACTUALLY is is
tempFiles.AddExtension("otf")
so
somehow you've taken a COLLECTION of files and tried to attach a file extension to it
what does that even mean?
also, the collection appears to be emptyhttps://learn.microsoft.com/en-us/dotnet/api/system.codedom.compiler.tempfilecollection.addextension
TempFileCollection.AddExtension Method (System.CodeDom.Compiler)
Adds a file name with the specified file name extension to the collection.
Here, lemme print the value of
file
alright
can you verify the file itself?
will do
otherwise, seems solid to me
So we do have a file
lemme check the file contents
well... ZACKPN-1 isn't a User...
And even then, there's no otf files in my Temp directory
Why would it make up a path that doesn't exist lol?
Ok @ReactiveVeina made some changes... Can confirm it creates an actual working
.otf
file at the path of variable file
... But the Font object created from it doesn't seem to work...it's a WORKING OTF file, specifically?
what you expect it to be?
does it work if you just hard-code the path to the source OTF file?
not the extracted one?
working otf
nope, fails with hardcoded path
this seems to be an issue with the Unity Font stuff 😦
yeah
or at least your understanding of how to use it
any chance it's a file permissions issue?
that's about my only other thought
I mean, I don't think so? I'm already creating/accessing the file from the same assembly, not to mention that I'm storing it in the game's file folder that it should have full access to
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.