A gold capsule runs toward a purple crystal on a sunlit stone bridge.

How to Build a 3D Pickup in Godot with Codex and the N4D API

How to Build a 3D Pickup in Godot with Codex and the N4D API

Watch the counter in the upper-right corner. When the player reaches the purple crystal, the crystal disappears and the count changes from 0/1 to 1/1. To build this pickup in Godot with Codex, you need two things: a visible 3D model and a trigger that knows when the player has collected it. You can replace the model without rewriting the trigger.

The player approaches the crystal on a sunny bridge and the counter advances to one.
Follow the pickup from 0/1 to 1/1. The animation follows the timing of the Godot run.

We generated the purple crystal through the N4D API and tested its GLB in Godot 4.7.2. You can inspect the crystal on N4D Community. To make your own pickup, start with the Codex prompt in step 1. If you already have a GLB, go straight to step 2.

Step 1. Godot Codex setup: generate one crystal GLB

For this step you need a Godot 4 project, Codex CLI, and an N4D account with API access and credits. If you already have a GLB, skip generation and build the pickup in step 2.

1. Open the project folder. Create or open a project in Godot, then find the folder that contains project.godot. Open that same folder in your text editor. If you haven’t installed Codex yet, follow the Codex CLI installation guide for your operating system.

2. Save the N4D instructions in a file. In your editor, create a plain-text file named exactly AGENTS.md alongside project.godot. Paste the entire block below into the file and save it. If the file already exists, append the block below its existing text. The file contains instructions only. You’ll enter your personal key in the next step.

Markdown
Use the N4D v1 API at https://api.neural4d.com/openapi/v1.
Read NEURAL4D_API_KEY from the environment. Keep the key out of files and logs.
Send it as Authorization: Bearer <KEY_FROM_ENVIRONMENT_VARIABLE>. Do not put the key in URLs.
Use the text to 3D model dreamtech/neural4d-2.5 with n: 1, with_texture: true, and with_pbr: true. Request a triangle mesh for the GLB.
Before submitting, check the request fields in https://docs.neural4d.com/en/v1-api-reference/3d-generation/create-3d-generation-tasks.md.
After a 202 response, save the top-level task ID, output type, and target directory to assets/neural4d/<TASK_ID>/task.json.
Use a client polling policy: start at 5 seconds, back off to 30 seconds, and stop waiting after 10 minutes per follow-up session.
Continue while the status is queued or processing. On succeeded, download the GLB. On failed, report the error.
If a task ID is available, keep checking that task and do not create a new one.
Create a generation task only when the user asks for a new generation. Do not create one while checking the key, checking an existing task, or downloading results.
If a submission times out before returning a task ID, do not resubmit. Check the request logs and your N4D account for a matching task first.
On 401, check the key. On 403, check the error code for access or credit issues. On 429, follow Retry-After when provided and resume polling the same task.
Download output.models[].model_urls.glb. Send the API key only to the API, never to output download URLs.

Append to AGENTS.md beside project.godot.

3. Enter your key and start Codex. Create and copy a key on the N4D API key page. Open a terminal in the project folder. For example, on Windows open the folder in File Explorer, type powershell in the address bar, and press Enter. Copy the complete command for your operating system, paste it into the terminal and run it. When prompted for the key, paste it and press Enter. Its characters stay hidden.

Windows PowerShell

PowerShell
& {
    $credential = [pscredential]::new('N4D', (Read-Host 'N4D API key' -AsSecureString))
    $env:NEURAL4D_API_KEY = $credential.GetNetworkCredential().Password
    Remove-Variable credential
    codex
}

Run in Windows PowerShell from the project folder.

macOS or Linux (Zsh or Bash)

Bash / Zsh
(
    printf "N4D API key: "
    IFS= read -rs NEURAL4D_API_KEY
    printf "\n"
    export NEURAL4D_API_KEY
    codex
)

Run in your project terminal on macOS or Linux.

The command opens Codex in this project. Complete Codex sign-in if prompted. The key is available to programs launched from this terminal for this session. If a separately opened desktop app or IDE cannot see it, continue in the Codex CLI session you just opened.

4. Check the setup before spending credits. Paste this message into the Codex chat:

Codex prompt
Read the N4D instructions in this project’s AGENTS.md. Check that you can see project.godot and that NEURAL4D_API_KEY is set in your execution environment. Report each result without showing the key. Do not submit a generation task.

Paste into Codex chat to check the setup.

Continue when Codex finds the project, the instructions, and the variable. If the variable is missing, enter the key again in the project terminal and launch Codex from there. Generation also requires network access to the N4D API and permission to write files in this project.

5. Generate one crystal. Paste the example below into the same Codex chat. This request submits one paid generation task.

Codex prompt
Use the N4D API to generate one 3D game pickup: a single upright purple crystal with a pointed tip, broad facets, and a pixel-art surface. Give it a flat base and no pedestal. Request a textured triangle mesh with PBR materials. Save the task ID, wait for completion, and download the GLB to assets/crystal.glb in this Godot project. Report the file path and credit usage if returned.

Paste into Codex chat when you are ready to use N4D credits.

How to tell it worked. Codex submits POST /3dmodels/generations, saves the returned task ID, then checks it with GET /tasks/task-info. On success it downloads the GLB from output.models[].model_urls.glb. In your project folder, open assets and check that crystal.glb exists and is larger than zero bytes. In Godot’s FileSystem dock, look for res://assets/crystal.glb. You can now continue to step 2.

If Codex returns a task ID but no file yet, paste the message below into Codex, replacing TASK_ID_HERE with that ID:

Codex prompt
Check N4D task TASK_ID_HERE. If it succeeded, download the GLB to assets/crystal.glb and report the file size. If it is still processing, tell me its status. Do not create a new task.

Replace TASK_ID_HERE with the saved ID before sending.

If you prefer a browser workflow, you can generate the crystal with the N4D text to 3D tool on the free plan, but downloading the GLB requires an active subscription. Download the GLB and start at step 2.

The 5 to 30 second interval and the 10 minute limit in the AGENTS.md instructions are this tutorial’s client-side settings, not API limits. Stopping the wait does not cancel the task on the server. If the wait ends while the task is still running, keep the task ID and check the task again later.

If you already have a task ID, continue checking that task instead of submitting again. If the current Codex session ends, start a new one in the project and point it at the saved task.json or the ID. If a submission times out before it returns a task ID, the outcome is unknown. Do not resubmit immediately. Ask Codex to check the original response and any saved task record, and check your N4D account for a matching task. Submit again only after you confirm the earlier request did not create a task. This avoids paying twice for one model.

For a 401, check which key the running session can read. For a 403, use the returned error code to check resource access or available credits. For a 429 on a status check, honor Retry-After if provided, then check the same task again. If the download is interrupted, use the original task ID to finish it. Do not generate again. You can compare the request and response with the N4D API quickstart.

If you want a longer walkthrough of the same API setup with a different coding agent, see how to use the N4D API with Claude Code.

Step 2. Make a cube collectible in Godot

Open the project in Godot 4. Start with a simple scene so you can test the pickup before adjusting the artwork. The cube below uses the same Area3D and score handler. When you collect the cube, it should disappear and the counter should reach 1/1.

The player approaches a placeholder cube on the courtyard bridge. Collected reads zero.
Start with a cube so you can test the pickup before importing a model.

Give Codex this instruction in the project folder:

Codex prompt
Build a small Godot 4 scene with a platform, a camera, a light, and a CharacterBody3D player that moves left and right with the arrow keys. Give the player a collision shape. Put an Area3D named Pickup on the platform with a visible placeholder cube and a spherical CollisionShape3D. Show “Collected 0 / 1” in the corner. When the player enters Pickup, hide the pickup and update the count to 1 / 1 exactly once. Make this the main scene.

Paste into Codex chat with your Godot project open.

Run the scene and move into the cube. Godot emits the area’s body_entered signal when the player enters its collision shape. In our demo the handler checks both the player and the current score:

GDScript
func on_pickup(body: Node3D) -> void:
    if body == actor and score == 0:
        score = 1
        pickup.hide()
        counter.text = "Collected   1 / 1"

Compare with the pickup handler in your Godot script.

What makes the crystal collectible?

In this scene the player is a CharacterBody3D. The visible crystal and a spherical CollisionShape3D are children of the pickup’s Area3D. When the player’s shape overlaps that sphere, the area emits body_entered. The line pickup.body_entered.connect(on_pickup) sends the entering body to the function above.

Two checks decide whether to award the point. body == actor identifies the player. score == 0 means this one collectible is still available. The first pass sets the score to one, hides the pickup and updates the label. On a return pass the score check is already false. You can swap the visible mesh and keep this behavior because the signal is connected to the area.

Step 3. Replace the cube with the crystal

Put the GLB at assets/crystal.glb inside the folder containing project.godot. Its Godot resource path is now res://assets/crystal.glb. For help with materials or scale on first import, see how to import and check AI models in Godot. Once the file appears in Godot’s FileSystem dock, ask Codex:

Codex prompt
Replace only the visible cube under Pickup with an instance of res://assets/crystal.glb. Center the crystal on the existing spherical trigger. Scale the model to fit the scene, keeping its proportions. Preserve the player, trigger, signal connection, and score label.

Paste into Codex chat after importing the GLB.

A purple crystal occupies the pickup position on the bridge. Collected reads zero.
Swap the cube for the crystal GLB and keep the pickup area in place.

How do you fit a new GLB to the pickup?

The crystal’s tip and base are easy to see in the editor, but the file’s origin can sit elsewhere. Our fit_model() function finds each mesh’s bounding box, converts it to the pickup’s local coordinates and combines the boxes. It divides 1.55 by the longest side of that combined box, scales the model uniformly, then moves its center to the center of the pickup.

We placed the pickup center at a height of 0.83 Godot units and gave its trigger a radius of 0.65. Those are settings for this platform. If a replacement gem looks oversized, change the target visual size first. If the gem looks right but you collect it too soon, inspect the trigger. The player has a collision shape of its own, so collection begins as soon as the two shapes overlap.

Two circular close-ups show the original player collider and crystal pickup area in Godot.
The close-ups show the actual Godot collision shapes. The smaller outline belongs to the player and the larger one to the pickup.

Step 4. Verify the pickup in play

Start to the left of the crystal and move toward it. Check three moments: the crystal is visible at 0/1, it disappears when the player reaches it, and the count stays at 1/1 when the player crosses the same spot again.

The crystal is gone from the bridge and the counter shows one out of one.
After contact, the crystal disappears and the counter reads 1/1.

We also ran the crystal scene with the player moving through the trigger and back across it. The first pass ended at 1/1. After the return crossing the crystal was still hidden and the counter was still 1/1.

The crystal is visible but the score stays at 0/1. What should I check?

What you see What to check
The player walks through the crystal. Enable Debug > Visible Collision Shapes and run the scene. Look for a shape on both the player and the pickup. If they overlap and the count stays at zero, check that the area is monitoring, its collision mask includes the player’s layer, and its body_entered signal calls the handler.
The crystal disappears while the player still looks far away. Look at the gap between the model and the trigger center. If the sphere sits to one side, recenter the visual. If it is centered but too large, reduce its radius and test the same approach again.
The crystal disappears but the label still reads 0/1. Trace the last line of the handler. Check that counter points to the label visible during play and that another script is not resetting its text.

To have Codex inspect your project, give it the observed symptom and the parts it should preserve:

Codex prompt
The crystal is visible, but the score stays at 0/1 when the player walks through it. Inspect the player’s collision shape and layer, the pickup’s shape and mask, and the body_entered connection. Show me which check fails and the smallest fix. Keep the current GLB and scoring rules.

Paste into Codex chat to inspect the current scene.

One import detail from this crystal may save you a debugging session. Godot logged “Not a PNG file” even though the gem rendered purple and the pickup worked. We checked the GLB and found three embedded JPEGs labeled image/jpg. Changing their format labels to image/jpeg in a project copy cleared the errors on reimport. If you see the same warning, check the embedded image bytes before changing any labels.

What else can you build with Codex and the N4D API?

Once the crystal works, keep the player and try one small change to the game rules. These are project ideas you can adapt from the single-crystal demo.

Three coins cross the courtyard bridge toward a key and a locked gate. A red vial sits on a side path.
What would you add to your level: a coin trail across the bridge, a key for the locked gate, or a health vial tucked away on a side path?

Coin trail

N4D asset
Make one coin GLB with a raised rim. Place three copies along a path.
Codex logic
Give each coin its own collected flag and add each pickup to the same counter.

PlaytestCross the middle coin twice. It should add exactly one point.

Locked door

N4D asset
Make a brass key with a large loop so players can recognize it at game scale.
Codex logic
Store a key flag on pickup. Have the door check it when the player approaches.

PlaytestTry the door before and after collecting the key. It should open on the second visit.

Health vial

N4D asset
Make a small vial with a broad base and a bright stopper.
Codex logic
Check the player’s health on contact. Consume the vial only when it can restore health.

PlaytestAt full health, the vial should stay. After damage, it should heal up to the limit and disappear once.

Godot pickup FAQ

Do I need the N4D API at runtime for the pickup to work?

No. In this project, Codex uses the N4D API during development to generate and download the crystal. When the game runs, Godot loads the GLB from the project. The player can collect the crystal and earn the point offline. Players do not need an N4D key.

Can I use my own GLB and skip the generation step?

Yes. Start with the placeholder cube in Step 2. Copy your GLB into the project’s assets folder, then use its actual filename in the Step 3 replacement prompt. Keep the pickup area and score handler when you swap the visible model.

Will the same scoring code work for several collectibles?

The demo tests one crystal. If several pickups share the same score == 0 check, collecting the first one blocks the rest. To extend the scene, give each pickup its own collected flag. On the player’s first overlap with that pickup, set its flag, add one to the shared score and hide that pickup.

Conclusion

Run through the crystal, then turn around and cross the same spot again. When the crystal stays hidden and the count stays at 1/1, try a coin, key, or health vial in its place. If you want to edit the replacement model in Blender first, see how GPT-6 Astra works in Blender. Keep the working pickup area and score handler. Changing only the visible child makes it easy to tell whether a problem belongs to the new model or to the game logic.

Scroll to Top