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

Custom Assets wont create if not registered in the AssemblyRegistry #2646

Open
Doprez opened this issue Feb 18, 2025 · 6 comments
Open

Custom Assets wont create if not registered in the AssemblyRegistry #2646

Doprez opened this issue Feb 18, 2025 · 6 comments
Labels
bug Something isn't working

Comments

@Doprez
Copy link
Contributor

Doprez commented Feb 18, 2025

Release Type: Official Release

Version: 4.2.0.2293

Platform(s): Windows

Describe the bug
When following the Custom Assets manual the Add asset option is there but upon clicking it the asset never gets created.

To Reproduce
Steps to reproduce the behavior:

  1. follow https://doc.stride3d.net/latest/en/manual/scripts/custom-assets.html
  2. put the templates and asset code in a separate external project
  3. see that the asset is shown in the Add Asset window
  4. Try adding the asset and see it does not get added

Expected behavior
The asset should be created.

Additional context
This is more for people to find a common issue if they are following a similar project structure of have multiple projects.
I will update the docs when I can and complete stride3d/stride-docs#390 to show that its done.

Current Fix
Just create a class called Module.cs in the external project with the asset files and add the below code with your namespace:

using System.Reflection;
using Stride.Core;
using Stride.Core.Reflection;

YOUR_NAMESPACE;

internal class Module
{
    [ModuleInitializer]
    public static void Initialize()
    {
        // "AssemblyCommonCategories.Assets" gets registered on startup of the project in GameStudio and allows the template to be created from a separate project.
        AssemblyRegistry.Register(typeof(Module).GetTypeInfo().Assembly, AssemblyCommonCategories.Assets);
    }
}
@IXLLEGACYIXL
Copy link
Collaborator

hmm maybe we should convert the entire module initializer to automatically register itself in the source gen?
and add user module initializers down below so we can get rid off the entire "standard module initializer" , so only need to register extras manually

@Doprez
Copy link
Contributor Author

Doprez commented Feb 18, 2025

That would be awesome! I guess it could create the module with either:

  • AssemblyCommonCategories.Assets
    • If it has Assets
  • AssemblyCommonCategories.Content
    • For something else? Im not 100% sure when this comes into play honestly.

You also need to make sure the project has the Stride.Core.Assets package that matches the Stride version so that has to be kept in mind. I dont know if that package could be used as the trigger to add the Module.cs class?

Semi separate but maybe another part of the discussion is automatically searching for .sdtpl files and adding them to the sdpkg of the project. It would simplify https://doc.stride3d.net/latest/en/manual/scripts/custom-assets.html#adding-a-section-for-the-add-asset-menu-inside-the-editor but maybe that should just be available in the GameStudio instead.

@IXLLEGACYIXL
Copy link
Collaborator

IXLLEGACYIXL commented Feb 18, 2025

detecting the referenced projects isnt hard, but as what should i register them, where are the side effects

i would need some ruling... if X then register as Y etc and based on the rules i change the source gen

@Kryptos-FR
Copy link
Member

It might not be that easy. You could reference Assets packages without defining new assets in your project (for example for some tooling) and registering that assembly (and its dependencies) would be wasteful and could potentially introduces compatibility issues (your tooling could without issue reference an older version of Stride.Assets, as long as that version doesn't get registered it's fine).

I prefer to not have too many "magic" behavior that might breaks unexpectedly. Remembering to had an initializer when needed is not a big deal as long as it is documented.

@IXLLEGACYIXL
Copy link
Collaborator

ok, so if there is a rule that is always true its just a one liner in the source gen , then leave it as is for now i guess

@Mark-Classen
Copy link

I tried going to a previous patch, I still had the same issue. I went to the first patch of the 4.2 version and I didn't have an issue there. There seems to be something added in the more recent versions causing this conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants