Access Assets by Coding
At this time, Script components do not support automatic reflection of asset fields in the UI, which means you cannot pass assets from the Assets panel directly into scripts.
As a temporary workaround, you can first assign the asset to a property on another component. Then, access that asset from your script by referencing the component. If you don't want the component to have any functional effect, you can simply disable it.
Texture
To use an Image component:
- Create a SceneObject and add an Image component to it
- Drag your desired Texture from the Asset panel into the Image component's Texture field
- In your script, locate the Image component and read its Texture property
- Use the Texture object as needed in your logic
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
onStart() {
let image = this.getSceneObject().scene.findSceneObject("Image")?.getComponent('Image') as APJS.Image;
if(image){
const tex = image.texture;
console.log(tex.getDepth(), tex.getWidth(), tex.getHeight() );
}
}
onUpdate(deltaTime: number) {
}
}
Material and Mesh
To use MeshRenderer and SkinMeshRenderer components:
- Create a SceneObject and add a MeshRenderer (or SkinnedMeshRenderer) component
- In the MeshRenderer properties, assign the target Mesh to the Mesh field and the target Material(s) to the Material field(s)
- In your script, get a reference to the renderer component and access its
mesh
andmaterials
properties - Modify the Mesh and Material objects as needed in your logic
To use a material in script, you need to know its uniform name, which can currently only be obtained by using Pin to Graph. (A proper API for accessing uniform names is planned for a future release.)
To assign the material to a SkinnedMeshRenderer, simply replace the MeshRenderer used in the example with a SkinnedMeshRenderer. All other steps remain the same. (This limitation will be removed in a future release.)
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
onStart() {
let meshRenderer = this.getSceneObject().scene.findSceneObject("Cube")?.getComponent('MeshRenderer') as APJS.MeshRenderer;
if(meshRenderer){
const mesh = meshRenderer.mesh;
console.log(mesh.name, mesh.boundingBox);
const mat = meshRenderer.mainMaterial;
console.log(mat?.name, mat?.getColor('_AlbedoColor'));
}
}
onUpdate(deltaTime: number) {
}
}

Animation
To use an Animator component:
Similar to how Mesh and Material are accessed through a renderer component, Animation objects can be accessed indirectly from the Animator component's animations
property.