Welcome to the Untold Engine! Follow these steps to set up your first macOS game project and get the engine running.
-
Open Xcode and navigate to:
File → New → Project. -
Select Game under the macOS platform.
-
Click Next and provide a name for your game (e.g., "MyRacingGame").
-
Make sure to set:
- Language: Swift
- Game Technology: Metal
-
Click Finish to create your project.
When Xcode creates your game project, it generates some default files that are not needed for the Untold Engine. Delete the following files:
GameViewController.swift
Renderer.swift
Shaders.metal
ShaderTypes.h
To remove them:
- Right-click each file in the Project Navigator.
- Select Delete and confirm.
To include the Untold Engine in your project:
- Open your Xcode project (e.g., "MyRacingGame").
- Go to: File → Add Packages...
- In the search field, enter the Untold Engine repository URL:
https://github.com/untoldengine/UntoldEngine.git
- Xcode will fetch the package. Select the appropriate version or branch (e.g.,
main
) and click Add Package. - Choose the target (e.g., your macOS game project) and click Add Package.
Now that the package is added, you can import the Untold Engine into your Swift files. The boilerplate code below initializes the engine and sets up a basic game scene.
Now, you will need to modify the AppDelegate file. We are going to do the following:
- Create a window
- Initialize the Untold Engine
- Create a game scene
Replace the contents of AppDelegate.swift
with the following:
import Cocoa
import UntoldEngine
import MetalKit
// The GameScene class is where you will declare and define your game logic.
class GameScene {
init() {
// Initialize game assets and logic here
}
func update(deltaTime: Float) {
// Game update logic
}
func handleInput() {
// Input handling logic
}
}
@main
class AppDelegate: NSObject, NSApplicationDelegate {
var window: NSWindow!
var renderer: UntoldRenderer!
var gameScene: GameScene!
func applicationDidFinishLaunching(_: Notification) {
print("Launching Untold Engine v0.2")
// Step 1. Create and configure the window
window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 1280, height: 720),
styleMask: [.titled, .closable, .resizable],
backing: .buffered,
defer: false
)
window.title = "Untold Engine v0.2"
window.center()
// Step 2. Initialize the renderer and connect metal content
guard let renderer = UntoldRenderer.create() else {
print("Failed to initialize the renderer.")
return
}
window.contentView = renderer.metalView
self.renderer = renderer
renderer.initResources()
// Step 3. Create the game scene and connect callbacks
gameScene = GameScene()
renderer.setupCallbacks(
gameUpdate: { [weak self] deltaTime in self?.gameScene.update(deltaTime: deltaTime) },
handleInput: { [weak self] in self?.gameScene.handleInput() }
)
window.makeKeyAndOrderFront(nil)
NSApp.setActivationPolicy(.regular)
NSApp.activate(ignoringOtherApps: true)
}
func applicationShouldTerminateAfterLastWindowClosed(_: NSApplication) -> Bool {
return true
}
func applicationWillTerminate(_ aNotification: Notification) {
// Cleanup logic here
}
}
-
Build and run your project in Xcode.
-
If everything was done correctly, you should see a window with a grid once you hit "Run".
Xcode may fail stating that it can't find a ShaderType.h file. If that is the case, simply go to your build settings, search for "bridging". Head over to 'Objective-C Bridging Header' and make sure to remove the path as shown in the image below
Xcode may fail stating linker issues. If that is so, make sure to add the "Untold Engine" framework to Link Binary With Libraries under the Build Phases section.
Next: Importing USDC Files