Loading assets (RUNTIME)

I have over 1000 JSON files imported into the project.
I set them all false on Preload in the inspector.

When I try to load them into memory in the project, I have an error
I copied the line of code from the project tutorial
Screenshots of code and error below :slight_smile:

assets.load requires an asset object (pc.Asset) not name (string): https://developer.playcanvas.com/en/api/pc.AssetRegistry.html#load

You can use assets.find to get the asset object by name and use that to load https://developer.playcanvas.com/en/api/pc.AssetRegistry.html#find

Which tutorial were you following?

1 Like

Still not working ,only this time object from json is empty

I found code tutorial here : https://playcanvas.com/project/406036/overview/tutorial-asset-registry

In the tutorial, it is passing a pc.Asset type to the load function as shown here:

UpdateAsset.attributes.add('c', {
    type: 'asset',
    assetType: 'model'
    if (app.keyboard.isPressed(pc.KEY_L)) {

Where the c attribute is of type asset.

Looking at the code from your project:

DataLoader.prototype.GetRaceData = function(RaceID) 
{   // raceID is "123456"
    var idJson = "";
    idJson = RaceID +".json";
    var asset = this.app.assets.find(idJson);
    RaceData = this.app.assets.find(idJson).resource;

It is trying to access the resource without waiting for the ready or load event. Read more in this section: https://developer.playcanvas.com/en/tutorials/using-assets/#assetregistry-events

In this particular case, create an event callback for the asset ready event and in the callback, process the resource which will be the JSON data.

1 Like

Is it possible to remove the asset from browser cache ?
asset.unload() removes it only from RAM , right ?

Yes, that’s correct, asset.unload() will remove it only from the RAM/VRAM.

I am not sure if you can remove something from the browser cache explicitly. There used to be a method that can instruct the browser to not keep a reference to that resource:


I haven’t tried it though myself.

You can’t remove from browser cache from the game as the browser handles it’s own caching. What’s the reason for wanting to remove from browser cache?