CREATE YOUR WORLD
Scripting

$ref & $unref

5min
the ref and out keywords in c# are used when passing references to variables or structures to methods in typescript, these keywords are not available, but in zepetoscript, you can achieve similar functionality using $ref and $unref functions description $ref(x?\ t) $ref creates a reference for a parameter $unref(x $ref)\ t releases the reference of a parameter and returns the original value for the example, let's set up a scene as follows add a 3d object, cube, to the scene in the inspector for the added cube, click "add component" and add a rigidbody add an empty gameobject to the scene write the refsample script below and add it to the gameobject created in step 3 import { gameobject, rigidbody } from 'unityengine' import { zepetoscriptbehaviour } from 'zepeto script' import testscript from ' /testscript'; export default class refsample extends zepetoscriptbehaviour { start() { // get the gameobject named "cube" const testobject = gameobject find("cube"); // get the rigidbody component from the "cube" object const testcomponent = gameobject find("cube") getcomponent\<rigidbody>(); // get the testscript component from the "cube" object const testscript = gameobject find("cube") getcomponent\<testscript>(); // create references to the components and object let tempobj = $ref(testobject); let tempcomponent = $ref(testcomponent); let tempscript = $ref(testscript); // check if the rigidbody component is not null if(tempcomponent != null) { // access the actual value of that reference let component = $unref(tempcomponent); console log(`component name ${component}`); } // check if the testscript component is not null if(tempscript != null) { // access the actual value of that reference let script = $unref(tempscript); script dotest(); } // check if the gameobject reference is not null if(tempobj != null) { // access the actual value of that reference let objname = $unref(tempobj); console log(`tempobj name ${objname name}`); } } } create another zepetoscript and write the testscript below import { zepetoscriptbehaviour } from 'zepeto script' export default class testscript extends zepetoscriptbehaviour { dotest() { console log(`testscript's dotest() is executed `); } } drag and connect testscript to the cube's inspector click the \[▶︎(play)] button to observe the results you can check the success of referencing objects, rigidbody components, and zepetoscript components in the console log window