xenko icon indicating copy to clipboard operation
xenko copied to clipboard

[Request] Lazy loading script properties that are assets.

Open dfkeenan opened this issue 8 years ago • 5 comments

Hi,

For quite a lot of things I have had to have a string property on a script and then use Content.Load in the scripts at the appropriate time. This is error prone. It also means you have to mark certain assets to be included in build as root.

I think it would be AWESOME to have properties that are of type Lazy<T> and Lazy<Task<T>> and be able to set them using Game Studio like normal properties. This removes the chance of error and would include asset in build. A good example of this would be:

public Lazy<Task<Scene>> NextScene { get; set; }

dfkeenan avatar Feb 24 '17 04:02 dfkeenan

I was thinking of it overnight instead of sleeping. I know....I have a problem. I think I have a Xenko addiction 😸

It might be simpler to use a type that acts as an Id (i.e. SiliconStudio.Assets.AssetId). And make ContentManager.Load accept one of these.

Or perhaps an Attribute that tells Game Studio this property is an asset url. And displays it as one of those asset picking controls. This would require no changes to serialization or ContentManager.

dfkeenan avatar Feb 25 '17 02:02 dfkeenan

We had some idea to auto-generate a .cs file containing all the root assets (aka contents on the runtime side) as constants that could be used at runtime. They could even be typed i.e. ContentId<Model> so that we have compilation-time check of asset existence and type in the code.

Maybe this could help for this use case.

xen2 avatar Feb 27 '17 09:02 xen2

While code-gen would be useful. I don't think it quite solves the Data-driven/design time scenario.

Personally, having something like ContentId<Model> as a script property type (or the attribute idea) and being able to set it in Game Studio would be preferable.

dfkeenan avatar Feb 27 '17 11:02 dfkeenan

Sure, this was a separate idea. I also agree something like a what you proposed would be quite useful (also had the same need several time).

xen2 avatar Feb 27 '17 16:02 xen2

Well if we could have both 🎉

It's a bit off topic...but where I'd really like to see code-gen is in UI. I think it would be AWESOME if UIPages worked similar to WPFs UserControl, in that it would generate a partial class with fields/properties for named UIElements and map them on load.

dfkeenan avatar Feb 27 '17 23:02 dfkeenan