Custom Asset Loading Issues With PlayCanvas React

Hello! I think I’ve found a bug in PC react relating to the component schema generator. This issue arose when trying to utilize custom asset loading & splat-transform. From what I’ve read they are supported uses for playcanvas react and the issue seems to be unintentional. I go over what I believe the issue is in depth on this issue Issue #315

TLDR My Implementation:

const fileSystem = new UrlReadFileSystem(typeof window !== 'undefined' ? window.location.origin : '');

async function load(filename: string, app: pc.Application, fileSystem: UrlReadFileSystem): Promise<Asset> {
  const gsplatData = await loadGSplatData(filename, fileSystem);
  const resource = new pc.GSplatResource(app.graphicsDevice, gsplatData);
  
  const asset = new Asset(filename, 'gsplat', { url: `/assets/temp-splats/${filename}` });
  asset.resource = resource;
  asset.loaded = true;
  app.assets.add(asset);
  
  return asset;
}

const Scene = () => {
  const [cur_asset, setCurAsset] = useState<Asset | null>(null);
  const app = CreateApp();
  
  useEffect(() => {
    if (!app) return;
    load('/assets/temp-splats/scene.ply', app, fileSystem)
      .then(setCurAsset)
      .catch(console.error);
  }, [app]);
  
  return (
    <Entity name="splat">
      {cur_asset && <GSplat asset={cur_asset} />}
    </Entity>
  );
};

When trying to pass a custom-constructed Asset to , I get:

Cannot set property id of #<GSplatComponent> which has only a getter
  at createComponentDefinition (validation.ts:382)

Currently my solution is to ditch the GSplat Component entirely and manually structure using the playcanvas engine api and that has been working wonderfully but is a good chunk more code. I’m unsure if its intended but the schema generator includes getter only props in its apply logic rather than skipping them or setting them to read-only. I have submitted a PR that fixes this but if its actually intended to use getter only props because of some kind of bypass or logic involving the dual uses of the Asset property being both a setter and a getter then it may be more than just my simple fix required.

I thought I’d post on the forums here just in case I missed something and to bring some more attention to the issue as it seems that the playcanvas react repo is updated much more infrequently than other playcanvas repositories. I’d love to hear any kind of feedback and its entirely possible I’ve made a mistake in my code but I’ve been able to recreate it in a few different methods and rule from what I can tell every other culprit out.

Thanks for reading!

My GitHub username is No-LAN-B

@Nolan please create a repo issue on this.

1 Like

I linked my repo issue # above its issue #315 here is the direct link: https://github.com/playcanvas/react/issues/315
I have also submitted a PR here:
https://github.com/playcanvas/react/pull/316

Note this issue may also be linked to issue 303 and directly solve it as well! https://github.com/playcanvas/react/issues/303

1 Like

I made some comments to copilots code review on the PR + some suggestions in regard to further implementation but so far there is no issue with the fix logically! Crossing my fingers we get to see some custom asset loading soon!.

Also to whoever made splat-transform give them my regards that tool is so cool. (on that note I have a feature request for it that should be simple to implement and would be very useful I’ll link the post here when i upload it to the forums) link: https://forum.playcanvas.com/t/splat-transform-feature-request/42000?u=nolan

I really appreciate the quick reply :smiley: you guys are the best!