Skip to main content

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:

  1. Create a SceneObject and add an Image component to it
  2. Drag your desired Texture from the Asset panel into the Image component's Texture field
  3. In your script, locate the Image component and read its Texture property
  4. 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) {
}
}
access texture

Material and Mesh

To use MeshRenderer and SkinMeshRenderer components:

  1. Create a SceneObject and add a MeshRenderer (or SkinnedMeshRenderer) component
  2. In the MeshRenderer properties, assign the target Mesh to the Mesh field and the target Material(s) to the Material field(s)
  3. In your script, get a reference to the renderer component and access its mesh and materials properties
  4. Modify the Mesh and Material objects as needed in your logic
note

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.)

uniform name
note

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) {
}
}
uniform name

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.

Copyright © 2025 TikTok. All rights reserved.
About TikTokHelp CenterCareersContactLegalCookies