Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant load resources #9

Open
BadChoice opened this issue Oct 15, 2023 · 13 comments
Open

Cant load resources #9

BadChoice opened this issue Oct 15, 2023 · 13 comments

Comments

@BadChoice
Copy link

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

        let path = Bundle.main.path(forResource: "JandaManateeSolid", ofType: "ttf", inDirectory: "Assets/Fonts")!
        let font:Font? = GD.load(path: path)
ERROR: No loader found for resource: /Users/crypto/Library/Developer/Xcode/DerivedData/godotest2-gpffnlaboxbwjxfsoygydhlmxanz/Build/Products/Debug/godotest2.app/Contents/Resources/Assets/Fonts/JandaManateeSolid.ttf (expected type: )
at: _load (core/io/resource_loader.cpp:281)

Or added as a reference group into the project as well, and event trying to use the res:// syntax, all with same error

        let font:Font? = GD.load(path: "res://" + path)
        let font:Font? = GD.load(path: "res://JandaManateeSolid.ttf)
@PadraigK
Copy link

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

@BadChoice
Copy link
Author

BadChoice commented Oct 16, 2023

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)

image

@migueldeicaza
Copy link
Owner

Is this SeiftGodotKit or SeiftGodot?

@PadraigK
Copy link

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?

@BadChoice
Copy link
Author

I'm using SwiftGodotKit, so no editor or project.godot file

@PadraigK
Copy link

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.

@migueldeicaza
Copy link
Owner

I suspect SwiftGodotKit needs some initialization to establish the base directory to load files from when using res://

@migueldeicaza migueldeicaza transferred this issue from migueldeicaza/SwiftGodot Oct 16, 2023
@BadChoice
Copy link
Author

BadChoice commented Oct 23, 2023

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

image

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")

@PadraigK
Copy link

PadraigK commented Nov 6, 2023

Is the ResourceLoader.load running inside the loadScene callback?

@BadChoice
Copy link
Author

yes, I have a Game.setup() method that ends up calling the ResourceLoad.load

@pcbeard
Copy link
Contributor

pcbeard commented Jan 28, 2024

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.

@hyouuu
Copy link

hyouuu commented Mar 30, 2024

I have a similar issue when trying to run the Dodge sample: https://gist.github.com/hyouuu/94a59fc5a5dbe071c736a39c68678325

Thoughts @migueldeicaza ?

@BadChoice
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants