Move an Entity - Basic Translation
What you'll learn:
- Moving an entity with
setProperty(.position) - Using
simd_float3direction vectors - Controlling speed with script variables
- Updating position every frame with
onUpdate()
Time: ~7 minutes
Prerequisites:
- Untold Engine Studio installed and a scene with any entity (a cube works great)
- Access to Xcode via Scripts: Open in Xcode (toolbar button)
What We're Building
A simple movement script that:
- Moves an entity steadily along a chosen axis
- Uses variables to control speed and direction
- Logs a message when movement begins
Step 1: Create the Script
- Open Untold Engine Studio
- In the toolbar, click Scripts: Open in Xcode (blue button)
- Click the
+button and enter the script name:MoveAnEntity - Click OK, then Xcode opens the Scripts package
When the script is created:
- The source file is added to your project
- You edit the script in Xcode
You'll see a template like this:
import Foundation
import UntoldEngine
import simd
extension GenerateScripts {
static func generateMoveAnEntity(to dir: URL) {
// Write your script here
}
}
This script is added to GenerateScripts, which is the entry point the engine uses to discover and generate USC scripts.
Step 2: Wire Up the Script
⚠️ IMPORTANT MANUAL STEP
The editor created your script file, but you need to tell the build system to generate it.
- Click Scripts: Open in Xcode (blue button in toolbar)
- In Xcode, open GenerateScripts.swift
- Add your script to the main() function:
@main
struct GenerateScripts {
static func main() {
print("🔨 Generating USC scripts...")
let outputDir = URL(fileURLWithPath: "Generated/")
try? FileManager.default.createDirectory(at: outputDir, withIntermediateDirectories: true)
// Add this line:
generateMoveAnEntity(to: outputDir)
print("✅ All scripts generated in Generated/")
}
}
Now run the GenerateScripts target (Cmd+R) to generate the .uscript files.
MPORTANT NOTES: The function name (e.g. generateMoveAnEntity) MUST match the tutorial’s script Only adjust that single line per tutorial The structure, wording, and warning must remain consistent across all documents
Step 3: Write the Script
Replace the function with this complete script:
import Foundation
import UntoldEngine
import simd
extension GenerateScripts {
static func generateMoveAnEntity(to dir: URL) {
let script = buildScript(name: "MoveAnEntity") { s in
// Runs once when the entity starts
s.onStart()
.setVariable("moveSpeed", to: 0.05) // units per frame
.setVariable("direction", to: simd_float3(x: 0, y: 0, z: 1))
.log("MoveAnEntity ready")
// Runs every frame
s.onUpdate()
.getProperty(.position, as: "currentPos")
.scaleVec3("direction", by: "moveSpeed", as: "step")
.addVec3("currentPos", "step", as: "nextPos")
.setProperty(.position, toVariable: "nextPos")
}
let outputPath = dir.appendingPathComponent("MoveAnEntity.uscript")
try? saveUSCScript(script, to: outputPath)
print(" ✅ MoveAnEntity.uscript")
}
}
Understanding the Code
moveSpeed + direction - Control how fast and where to move
- Speed is a scalar; direction is a vector (x, y, z)
- Change either without touching the rest of the script
getProperty(.position, as:) - Reads the current position
- Positions are
simd_float3values
scaleVec3() + addVec3() - Build the new position
- Scales the direction by speed
- Adds it to the current position for smooth motion
setProperty(.position, toVariable:) - Applies the updated position
- Runs every frame inside
onUpdate() - Keeps the movement continuous while Play mode runs
Step 4: Build the Script
- In Xcode, press
Cmd+Rto run the GenerateScripts target and generate the.uscript(optional:Cmd+Bfirst to verify the build). - Watch for the Xcode run output:
🔨 Generating USC scripts...
✅ MoveAnEntity.uscript
✅ All scripts generated in Generated/
First build? May take 30-60 seconds to download engine dependencies. Subsequent builds are much faster.
Step 4: Attach to an Entity
- Return to Untold Engine Studio
- Select any entity in your scene (a cube or platform)
- In the Inspector panel, click Add Component → Script Component
- In the Asset Browser, find
MoveAnEntity.uscriptunder Scripts/Generated - Double click on the
.uscript. The script will be linked to the entity
Step 5: Test It!
- Click Play in the toolbar
- Watch the entity move steadily along the +Z axis
- Check the Console view to confirm:
MoveAnEntity ready - Click Stop to exit Play mode
Understanding the Output
- The entity moves every frame toward +Z
- Speed comes from
moveSpeed; direction comes fromdirection - To stop movement, disable the Script Component or set speed to 0
⚠️ Placement Note: If the entity is already near a boundary, lower the speed or adjust the start position to avoid moving out of view.
Modify and Experiment
Try these changes to learn more:
Move Upward Instead
.setVariable("direction", to: simd_float3(x: 0, y: 1, z: 0))
Slow or Fast Motion
.setVariable("moveSpeed", to: 0.01) // slower
// or
.setVariable("moveSpeed", to: 0.15) // faster
Pause After a Distance
s.onUpdate()
.getProperty(.position, as: "currentPos")
.ifGreater("currentPos.z", than: 10.0) { n in
n.setVariable("moveSpeed", to: 0.0) // stop after z > 10
}
.scaleVec3("direction", by: "moveSpeed", as: "step")
.addVec3("currentPos", "step", as: "nextPos")
.setProperty(.position, toVariable: "nextPos")
After making changes:
- In Xcode, press
Cmd+Rto rerun the GenerateScripts target and regenerate the scripts (Cmd+Boptional first). - Click Reload in the Script Component Inspector
- Test in Play mode
What You Learned
✅ Creating a movement script in Untold Engine Studio
✅ Using variables for speed and direction
✅ Updating position every frame with onUpdate()
✅ Building and attaching scripts to entities
✅ Testing motion in Play mode