GameLogic
repersents the core management component of the game. It receives all in-game events and distributes them to the appropriate subsystems, effectively reducing code coupling.Transponder
component automaticlly detects the interaction and passes the player approaching event to the GameLogic
component. In response, UIFactory
instantiates a UI panel for user input.GameLogic
.TripoClient
component (Note: a Vaild TripoAPIKey must be provided beforehand)TripoAPI
assembles the request , sends it and begins polling the server at regular intervals to check for updates. Once sucessesful, the player receives a TakID for the generated model from the Tripo Server. This TaskID is then used to request skeleton generation.TripoAPI
returns the model's download URL to TripoClient. TripoClient
then loads and parses the GLB-format model via the glTFfast plugin.RuntimeHumanoidAvatarBuilder
component is mounted onto the model. This component maps the GLB model's skeleton to Unity's Humanoid Avatar system, enabling animation retargeting.TripoClient
instantiates the model in the scene. At this point, developers can use existing humanoid animation resources to drive the newly generated model.The GameLogic
compoent listens for the player's keyboard input to dynamically switch control between the player and the generated model. Specifically, it adjusts camera priority and reassigns the ThirdPersonController
control target.Unity Version: 2022.3.55
Source code and scenes Path: Assets-LowPoly Environment Pack - Demo - Demo1
Create a New Project
Import Required Resource Pac
Please open your browser and go to the Unity Asset Store. Search and download the following free packages (also available in the provided project files):
Add to My Resources, and in subsequent pop-ups, click "Open in Unity" and download.
After downloading each package, go to Unity > Assets which is on the top of the Unity Menu > Import Package > Custom Package , and import them one by one. Click Import on each prompt.
Some imported materials may appear pink(indicating shader issue). To convert:
Option 1: Install via Git (requires a local Git environment)
Option 2: Download from Tripo official website, which includes the glTFast plugin as well.
To set up your custom environment:
Navigate to: Assets > StarterAsset > ThirdPersonController > Prefabs
Drag the following three prefabs into the Hierarchy panel:
The above setup uses the third-person controller script provided by Unity. At this point, click the Play button in the Unity toolbar, you can use the WASD keys to control the character's movement. The character and the camera should now move and adjust it accordingly!
When the player approaches a specific object, a UI input panel should appear. When the player moves away, the panel should disappear.
Transponder
, and open the script with Cursor.Please generate a Unity C# script named Transponder that triggers OnPlayerEnter when a GameObject with tag "player" enters the collider, and OnplayerExit when the player exits.
Right-click in the scene > Create Empty, rename it GameLogicManager (Serves as the logic container).
GameManager
, which will handle the core logic for the scene.We quote the Transponder component and then listen for events when players enter or exit. The reference prompt words are as follows:
Please generate a Unity C# script named GameManager that listens to.
After saving the script, drag the GameManager script onto the GameManager object and drag the Tranponder component into the Tranponder field. This completes the listening for player entry and exit events.
In the Hierarchy, right-click > UI > Panel, to create a new panel.
Add 2 compoents in children under the panel:
Adjust layout and positioning using the Game view as a preview.
Once finished, drag the entire Panel object into the Assets Folder to create a prefab.
Note: If you are using TextMeshPro,make sure to assign a Chinese-compatible font, such as NotoSansSC SDF, to avoid square-shaped characters in the text.
InputDialog
Script: Handle Input LogicReference Promot:
ThirdPersonController
)Mount the InputDialog component to the InputDialogPrefab. Drag the corresponding Text and InputField objects into their respective fields on the component (Dependencies).
Create a new C# script named UIFactory
Reference Promot:
This component acts as an intermediary to decouple UI creation logic from game event handling.
Double-check whether all component dependencies are properly assigned.
In GameManager object, assign:
UIFactory
component on GameLogicManager object.Testing: Click Play in Unity.
Note: Our source file has a fixed position for where the panel is generated. Modify this value according to the Transform properties of the Trigger you selected. Alternatively, you can set the Canvas > RenderMode of the UI prefab to ScreenSpace - Overlay, so that the UI will be rendered in screen space data and will not enter world space.
At this stage, we are not yet able to submit prompts to the Tripo server in real-time. However, the necessary code for prompt submission, network requests, model generation, skeleton rigging, mapping, adapter, and animation retargeting is ready in place. These scripts will be fully integrated into the Tripo for Unity plugin in future updates. (Note: Please make sure a UIEvent system exists in your scene before proceeding; otherwise, the UI will not respond!)
In the Unity Project panel (usually on the left,), locate the source files TripoClient.cs
, TripoAPI.cs
, and RuntimeHumanoidAvatarBuilder.cs
from you download folder.
Here's what each script does:
TripoClient.cs and TripoAPI.cs
:Handle prompt submission and network communication with the Tripo server.RuntimeHumanoidAvatarBuilder
.cs :Maps the model's skeleton to Unity's humanoid rig using the GLTFast plugin.TripoClient.cs and TripoAPI.cs
represent lite versions of the Tripo For Unity
plugin but with rigging functionality. We will continue to update and streamline this process in future releases.
TripoClient.cs
and TripoAPI.cs
onto this new object to attach the scripts.Since we have upgraded the player input system, we need to update the prompt transmission logic in GameManager. By default, the GameManager script should already be listening to OnPlayerEnter and OnPlayerExit events. If you are working with AI-generated code or chaining logic across multiple components, It's helpful to paste previously generated code as context.
The script that we provided has already defined the callback function when GameManager
issues an instance call to UIFactory
. Definitely, there are other solutions, but in this case, the prompt that can be use to complete this part of the logic can be seen as the following.
Updated Behavior: In GameManager
script
UIFactory
instantiate an input dialog (InputDialog prefab).Once the player finishes entering a prompt, it will passed to the TripoClient script with , with a call example of tripoClient.TextToModel(prompt, pos);. Modify the associated scripts.
Modify GameManager.cs:
Test your Setup
Now you are ready to generate your own AI model in Unity. Enjoy building!
Once the model has been generated, the next step is to map existing animation resources to your model's skeleton. Ensure the RuntimeHumanoidAvatarBuilder
script has been added to your project. This script handles the mapping from the humanoid GLB skeleton to Unity's Avatar, and the TripoClient script will automatically mount it to the generated model.
Let's first organize the structure and dependencies of the project. Before the game stares, except for environmental objects, the custom GameObjects should be in the following state. Expand each script component and ensure all fields are correctly assigned. If you encounter any issues, compare them with the source files to check for incorrect component assignment.
Otherwise, in our demo, the model is a combat mech, so its Transform > Scale property is enlarged tenfold. This also applies to its Controller-related properties.
Select the ModelContainer compoment and sequentially add the following components (all provided by the Starter Assets package):
In the Third Person Controller component, set the Camera field to the MainCamera in the scene.
Create an empty compoents in children, name it ModelCamera, and add a CinemachineFreeLook component to it (you need to import the Cinemachine plugin, which is included in the Starter Assets package).
Then create a compoents in children under ModelContainer, name it CameraRoot, and adjust its Y-coordinate to 5 (waist height of the model). Assign both the Follow and LookAt fields of ModelCamera to CameraRoot. Now the camera will follow the model's movement.
At this point, the transformer should play its idle animation but cannot be controlled yet.
Those components: CharacterController, PlayerInput, ThirdPersonController, BasicRigidBody, and StarterAssetsInputs, are provided by Unity's StarterAssets and handle player input. The Animator component controls the animation, and the Avatar generated by the RuntimeHumanoidAvatarBuilder will be automatically also assigned to the Animator's Avatar field.
To Test:
Now during runtime, the transformer can be controlled. Then the final step is to implement logic for control switching.
Update the following logic in the Update function of your GameLogic script:
When entering the transfomer:
When exiting the transformer:
Once the above logic is complete, pressing the F key allows the player to enter and control the transformer. Pressing the F key again switches control back to the player, while the transfomer remain in place, but the player reappears excatlly at the transfomer's location.
At this point, the demo is functionally complete. If you want to polish the experience, you can:
Congratulations!
Thank you for your hard work! You have now completed the entire demo. You can freely generate and control the transfomer models using your own ideas and assets.
Need Help?
If you encounter any difficulties or have feedback for TripoGame, please feel free to contact us at our official email! tripogame@vastai3d.com. We'd love to hear from you!
This tutorial is designed to demonstrate how the Tripo API can be used in real-time gameplay. The game design itself is for reference only. Hoping to proactively address potential issues that developers may encounter.
Currently, the demo only supports generating humanoid models due to rigging requirements. If animation appears abnormally due to the unstable AL-generated skeleton weights, use the Avatar Mask to block problematic body parts animation. For example, the source file already disables hand animation in the NoArmPerson Controller.
For faster generation, you can use the TripoV2/TripoV1Turbo. Simply replace the model_version number "v2.5-20250123" in the TripoAPI script with
FBX and GLB models have different orientations, which may lead to dependency issues when importing. If you need to import FBX, use plugins such asTriLib to load the model and handle adaptations accordingly.