Check out our latest project ✨ OpenChapter.io: free ebooks the way its meant to be 📖

Safe Resource Picker

An asset by HauntedBeekeeper
The page banner background of a mountain and forest
Safe Resource Picker hero image

Quick Information

0 ratings
Safe Resource Picker icon image
HauntedBeekeeper
Safe Resource Picker

Get the type safety of the native Godot resource picker with the performance benefits of storing resource paths instead of resources.By just adding a custom type hint to your `@export` properties, you can use the Resource Picker control in the Inspector, but the values will be stored as uid strings instead of external references.This means that loading your Resource will load JUST your Resource, and not all of its external references.This can be a huge performance boost when, for example, you have a shopkeeper with many items -- you don't need to load every item's 3D models if you're only showing their names in the shop!

Supported Engine Version
4.4
Version String
1.0.1
License Version
MIT
Support Level
community
Modified Date
1 month ago
Git URL
Issue URL

Safe Resource Picker Editor Plugin

README Works with Godot 4.4 and higher README MIT Licensed

If you've ever written @export var scene: PackedScene or @export var item: CustomResource in your resource or node to store data, then you're benefitting from the type safety of the Godot Inspector ensuring that only PackedScene or CustomResource values can be stored in your property. However, now your resource or node contains that entire resource, too, and whenever your resource or node loads, so does that resource!

It's much more performant to write @export var scene_path: String and then use var scene: PackedScene = load(scene_path) later, but now the Inspector just shows a text field for that property, and anything can go in there!

With the Safe Resource Picker, you can write @export_custom(SRP_HINT.RESOURCE_PATH, "PackedScene") var scene_path: String and get the performance benefits of only storing a string with the Inspector interface of selecting a resource!

Installation

Download from the Godot Asset Library or GitHub and put the safe_resource_picker directory in your project's res://addons directory. Go to your Project Settings and enable the Safe Resource Picker plugin.

Usage

Anywhere you want to store a Resource path, use @export_custom(SRP_HINT.RESOURCE_PATH, "ResourceType"), like so:

@export_custom(SRP_HINT.RESOURCE_PATH, "PackedScene") var scene_path: String

func get_scene() -> PackedScene:
    return load(scene_path)

For an Array of Resources, use the same @export_custom annotation on an Array, Array[String], Array[StringName] or PackedStringArray variable.

ResourceUidLoader

There's also a ResourceUidLoader node that uses ResourceLoader.load_threaded_request behind the scenes to load resources and emit signals when they're loaded. This exists for the Array editor implementation, but can likely be used by your own project as well. As it inherits from Node, you will either need to add it to your scenes or add it to your project as an Autoload to use it.

Limitations

The experience for Arrays is slightly different than the native Godot Array inspector.

Dictionaries with Resources as the keys or values are not supported. As recreating the Dictionary editor in GDScript would be a massive undertaking, this is unlikely to change.

Future

  • This plugin will be maintained to ensure its compatibility with all future Godot versions.
  • If any bugs are found, they will be fixed.
  • Documentation may be updated to be more clear if needed.
  • In the event that a new version of Godot surfaces Dictionary-editing controls in GDScript, Dictionary support may be added at that time.
  • I would like to make the Array editor match the native Godot editor a bit better (highlighting the panel when it's expanded) but to my knowledge this is not feasible unless the engine surfaces more editor controls in GDScript as well.
  • The Godot Editor doesn't seem to translate error strings right now. If this ever changes, it would be nice to have translations for the two error strings this plugin can emit.
  • Other new features are unlikely.

Get the type safety of the native Godot resource picker with the performance benefits of storing resource paths instead of resources.

By just adding a custom type hint to your `@export` properties, you can use the Resource Picker control in the Inspector, but the values will be stored as uid strings instead of external references.

This means that loading your Resource will load JUST your Resource, and not all of its external references.

This can be a huge performance boost when, for example, you have a shopkeeper with many items -- you don't need to load every item's 3D models if you're only showing their names in the shop!

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
Safe Resource Picker icon image
HauntedBeekeeper
Safe Resource Picker

Get the type safety of the native Godot resource picker with the performance benefits of storing resource paths instead of resources.By just adding a custom type hint to your `@export` properties, you can use the Resource Picker control in the Inspector, but the values will be stored as uid strings instead of external references.This means that loading your Resource will load JUST your Resource, and not all of its external references.This can be a huge performance boost when, for example, you have a shopkeeper with many items -- you don't need to load every item's 3D models if you're only showing their names in the shop!

Supported Engine Version
4.4
Version String
1.0.1
License Version
MIT
Support Level
community
Modified Date
1 month ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers