Open BadChoice opened 11 months ago
You're on the right track with the second approach, I think it's just returning something that's not a Font
.
let resource = GD.load(path: "res://JandaManateeSolid.ttf)
GD.print(resource)
and see what type it's giving you
Hi I tried this 4 cases,
let path = Bundle.main.path(forResource: "JandaManateeSolid", ofType: "ttf", inDirectory: "Assets/Fonts")!
let resource = GD.load(path: path)
print("[TBD] Resource: \(resource)")
let path2 = Bundle.main.path(forResource: "JandaManateeSolid", ofType: "ttf")!
let resource2 = GD.load(path: path2)
print("[TBD] Resource: \(resource2)")
let resource3 = GD.load(path: "res://JandaManateeSolid.ttf")
print("[TBD] Resource: \(resource3)")
let resource4 = GD.load(path: "res://Assets/Fonts/JandaManateeSolid.ttf")
print("[TBD] Resource: \(resource4)")
all of them returned nil
This is how I store the files (one as reference folder and the other one as group)
Is this SeiftGodotKit or SeiftGodot?
When I do this:
let font = GD.load(path: "res://assets/Kenney Thick.ttf")
GD.print(font)
It produces: // Optional(<FontFile#-9223372004793514644>)
so I would have expected your fourth option to work 🤔
Is your project.godot
at the root? Anything unusual about the font file itself? If you try opening the godot project once, does the ttf file appear in resources?
I'm using SwiftGodotKit, so no editor or project.godot file
Ah, I see. I've used this in my SceneGen project like this: https://github.com/PadraigK/SceneGen/blob/b57e157fef771275da6c9b94efbab389c69f19ce/Sources/SceneGen/Helpers/GodotTools.swift#L26-L35
I found I did need a project file to be able to access resources at all, but it can probably be very minimal.
I suspect SwiftGodotKit needs some initialization to establish the base directory to load files from when using res://
I added a simple project.godot
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=5
[application]
config/name="Godot name"
config/features=PackedStringArray("4.0")
[debug]
gdscript/warnings/unused_parameter=0
[display]
window/size/resizable=true
[importer_defaults]
texture={
"compress/channel_pack": 0,
"compress/hdr_compression": 1,
"compress/high_quality": false,
"compress/lossy_quality": 0.7,
"compress/mode": 0,
"compress/normal_map": 0,
"detect_3d/compress_to": 0,
"mipmaps/generate": false,
"mipmaps/limit": -1,
"process/fix_alpha_border": true,
"process/hdr_as_srgb": false,
"process/hdr_clamp_exposure": false,
"process/normal_map_invert_y": false,
"process/premult_alpha": false,
"process/size_limit": 0,
"roughness/mode": 0,
"roughness/src_normal": ""
}
[rendering]
2d/snap/snap_2d_transforms_to_pixel=true
2d/snap/snap_2d_vertices_to_pixel=true
textures/canvas_textures/default_texture_filter=0
and loaded the godot like this
runGodot(
args: ["--path", Bundle.main.resourcePath ?? ""],
initHook: registerTypes,
loadScene: loadScene,
loadProjectSettings: { settings in
settings.set(property: "application/config/name", value: "TBD Property")
}
)
where bundle.main.resourcePath is where the project.godot
file are, as well as the Assets
But still all the different load methods return nil, I also tried with resource loader itself, and with another filetype with no luck
let a = ResourceLoader.load(path: "res://Assets/Music/8bits-retro.mp3")
Is the ResourceLoader.load
running inside the loadScene
callback?
yes, I have a Game.setup() method that ends up calling the ResourceLoad.load
From my understanding GD.load()
only works with "res://" URLs. You have to import resources into a Godot project before you can access them with GD.load()
. You can then export your Godot project as a .pck file and resources can also be loaded from that. This is how you'd want to ship your game.
I have a similar issue when trying to run the Dodge sample: https://gist.github.com/hyouuu/94a59fc5a5dbe071c736a39c68678325
Thoughts @migueldeicaza ?
I still haven't been able to get resources working on a pure swiftgodokit app, anybody got any luck with that? I creted a godot project, imported the files there, and trying to use it, but no luck either
I'm trying to load resources and it seems it is not working
I tried different ways, but always same error Full path, with the file referenced as as folder
Or added as a reference group into the project as well, and event trying to use the res:// syntax, all with same error