Unable to access Text Asset by Id

I have added an attribute called words and selected a text file in the editor. However when trying to access the resource by Id it is undefined.

var GameManager = pc.createScript('gameManager');
GameManager.attributes.add('words', { type: 'asset', assetType: 'text', array: false });

// initialize code called once per entity
GameManager.prototype.initialize = function() {
var asset = this.app.assets.get(this.words);

variable ‘asset’ above is undefined. I am preloading the text file so I am not sure why it would be undefined.

Hi @John_Logan and welcome!

It looks like you are doing kind of the same on line 2 and 6. I expect line 6 should be something like below?

var asset = this.words.resource;

Or you can use the asset ID from the editor on your current line 6 and don’t use the attribute of line 2.

1 Like

that was exactly it, thank you!