How to load cc.Effect from extension package?

I’m writing extension for the editor and need to load dynamically cc.Effect defined by .effect file in the extension package folder. I found that if I want to load resource dynamically it should be placed in ‘resources’ folder. But what about resource in the extension package? Where to place it and how to define to be able to load it dynamically?

Hi @slackmoehrle @jare @huanxinyin @pandamicro,
@ymiroshnyk is writing an awesome extension to Cocos Creator that would be beneficial for everyone. Could you give him a helping hand?

Thanks a lot for your time!

@yufang.wu do you know?

@SantyWang please take a look.

Please see this post, How to define a bundle in extension package?

Let me describe my idea in details, so you could see all the picture.
I have a component in the extension package. This component can be attached to a node in the editor. The component plays particle effects. So it should work in the editor.
Also the component uses cc.Materials created from the cc.EffectAsset loaded from .effect file. These are materials which automatically assigned to the component accordingly particle effect chosen.

For now I’m loading .effect file via cc.resources.load() and it is located in assets/resources folder. And my idea is to move everything I need inside the package including this .effect file. So the question is how can I load this effect in the editor environment as well as in a running application?

As @SantyWang mentioned in the post How to load cc.Effect from extension package? , a bundle is not an option, as it can’t be loaded in the editor environment. So are there other options to make it?

One of possible solutions would be to load the effect from a string which contains source of the effect. Is it possible?

there are two ways I can imagin to solve this problem:

  1. Define a property to reference a .effect file in your component,

  2. Use assetManager.loadAny(uuid) to load an effect in Editor

One of possible solutions would be to load the effect from a string which contains source of the effect. Is it possible?

Sorry, this feature is not currently supported

Thank you @SantyWang.
assetManager.loadAny() works like a charm! I can easily get uuid of the resource in the editor and load the resource by this uuid.

And another one question relative to loadAny(), if you would be so kind.
Can I load a sprite frame with loadAny() by it’s pathin assets (like ‘assets/Textures/some_sprite’)?

Can I load a sprite frame with loadAny() by it’s pathin assets (like ‘assets/Textures/some_sprite’)?

loadAny can only load paths in the Asset Bundle, if assets/Textures is a bundle, you can load sprite frame likes following:

cc.assetManager.loadAny({ 'path': 'some_sprite', 'type': cc.SpriteFrame, 'bundle': 'Textures' }, onProgress, onComplete);

note: This way is still only available at runtime, not editor.

Thank you very much for the info.

@SantyWang, I found another one issue with loadAny(). For a some reason it doesn’t want to load assets in a built game, in the editor and dev mode everything works fine though.

I try to load material by UUID. I have such call in my script:

And in the build I have following error:

The most interesting part I believe is in the error message:

Error: download failed: undefined/36/36f4c373-11c5-4bdc-98f9-505f60bc27d1.json, status: 404(no response)

here is something undefined in the start of the path.

This loading script is called from onLoad() of one of components in the scene.

Do you have any clue on how to resolve this?

By the way, effect can’t be loaded in the build as well. The error is the same:

NeutrinoContext: can’t load effect ‘NeutrinoEffect’ with UUID b8K8qQyK1DF63rgBEBZeOS. Error: download failed: undefined/b8/b82bca90-c8ad-4317-adeb-80110165e392.json, status: 404(no response)

Materials and the effect are placed inside my extension package. Not in the bundle.
There is a component on the scene which uses materials, so they are referenced and shouldn’t be optimized in any way.

You still need to use asset bundle to load asset in runtime, loadAny is just a use in the editor