URT3D Docs
  • πŸ“˜Welcome to URT3D Docs
  • Getting Started
    • πŸš€Quickstart
  • Basics
    • 🌐Introduction to URT3D
    • πŸ”„How to Convert Your Files
    • ⬆️Upload Tips and Guidelines
    • πŸ“¦Using Your Converted Files
    • πŸ› οΈTroubleshooting Conversion
  • πŸ“‚ Developers
    • πŸ‘©β€πŸ’»Getting Started with the SDK
    • πŸ‘¨β€πŸ’»Unity Integration Guide
    • πŸ—οΈCore Concepts & Architecture
    • 🧬Traits System
    • ✍️Scripting System
      • 🧾MiniScript Recipes
    • πŸ“˜API Reference
    • πŸ’‘Examples and Best Practices
    • πŸ›°οΈAdvanced Topics
Powered by GitBook
On this page
  1. πŸ“‚ Developers

Examples and Best Practices

Learn practical ways to structure your URT3D workflow β€” including example scripts, reusable traits, asset pooling, and real-time interactivity patterns.

PreviousAPI ReferenceNextAdvanced Topics

Last updated 1 month ago

πŸ“˜ Looking for detailed implementation docs? This page gives you a high-level overview, but you can always dive deeper in the official SDK documentation on GitHub:

This page shares real working patterns for using the URT3D SDK effectively β€” with examples in both C# and MiniScript.


πŸ”Ή Loading Multiple Assets in Sequence

Use async/await to load and place assets one after another.

public async Task LoadSequentially(string[] paths)
{
    foreach (var path in paths)
    {
        var asset = await Asset.Construct(path);
        if (asset != null)
        {
            float xPos = Array.IndexOf(paths, path) * 2.0f;
            asset.GetTrait<TraitPosition3d>()?.SetValue(new Vector3(xPos, 0, 0));
        }
    }
}

πŸ”Ή Using Callbacks for Fire-and-Forget Loads

When sequencing isn’t needed:

public void LoadAssetByGuid(Guid guid)
{
    Asset.Construct(guid, asset => {
        if (asset != null)
            Debug.Log("Loaded: " + asset.Metadata.NameInstance);
    });
}

πŸ”Ή Best Practice: Always Check for Traits

var positionTrait = asset.GetTrait<TraitPosition3d>();
if (positionTrait != null)
{
    positionTrait.SetValue(new Vector3(0, 1, 0));
}

Use null conditional operators for cleaner one-liners:

asset.GetTrait<TraitPosition3d>()?.SetValue(new Vector3(0, 1, 0));

πŸ”Ή MiniScript: Float Animation on Hover

This example makes an object bob up and down when hovered.

interactable = GetTrait("Interactable")
position = GetTrait("Position3d")
originalY = position.GetValue().y
hovering = false

function OnStart()
    interactable.OnHoverEnter = OnHoverEnter
    interactable.OnHoverExit = OnHoverExit
end function

function OnHoverEnter()
    hovering = true
end function

function OnHoverExit()
    hovering = false
end function

function Update()
    pos = position.GetValue()
    if hovering then
        pos.y = originalY + 0.2 * Math.Sin(Time.Now * 5)
    else
        pos.y = originalY
    end if
    position.SetValue(pos)
end function

πŸ”Ή Best Practice: Use Custom Events

Let scripts or C# trigger behaviors from a distance:

MiniScript:

function OnCustomEvent(eventName)
    if eventName == "open" then
        anim = GetTrait("Animatable")
        anim.PlayAnimation("Open", false)
    end if
end function

C#:

wrapper.TriggerCustomEvent("open");

πŸ”Ή Object Pooling for Performance

Use a queue-based system to reuse loaded assets:

private Dictionary<string, Queue<Asset>> _pools = new Dictionary<string, Queue<Asset>>();

public void ReturnAsset(string name, Asset asset)
{
    asset.Actor.GameObject.SetActive(false);
    _pools[name].Enqueue(asset);
}

public Asset GetAsset(string name)
{
    if (_pools[name].Count > 0)
    {
        var asset = _pools[name].Dequeue();
        asset.Actor.GameObject.SetActive(true);
        return asset;
    }
    else
    {
        Asset.Construct(path, newAsset => {
            newAsset.Actor.GameObject.SetActive(true);
        });
        return null;
    }
}

πŸ”Ή Best Practice: Prefab Your Setup

  1. Drag a URT3D asset into the scene

  2. Configure traits and scripts in the Inspector

  3. Create a Unity prefab from that object

  4. Reuse across levels without setup duplication


πŸ’¬ Need Help?

πŸ“© Email us at:

πŸ’‘
urt3d-sdk_unity β€Ί Documentation
πŸ—¨οΈ Join our Discord creator community
support@urt3d.com