Dava
February 24, 2021, 11:55am
#1
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
yaustar
February 24, 2021, 11:59am
#2
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
Dava
February 24, 2021, 1:20pm
#3
yaustar
February 24, 2021, 1:30pm
#4
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)) {
app.assets.load(this.c);
}
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);
console.log(asset.name);
this.app.assets.load(asset);
RaceData = this.app.assets.find(idJson).resource;
Dog1=RaceData.Dog1;
console.log(Dog1.length);
};
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
Dava
February 25, 2021, 9:54am
#5
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:
https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL
I haven’t tried it though myself.
yaustar
February 25, 2021, 9:57am
#7
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?