When or why would someone use a programming language (Swift, Java, C++, Rust etc…) over an engine like Unity?

You need to write a game without an engine when you have a game with very unique technical challenges which are not sufficiently covered by general-purpose game engines.

General purpose game engines like Unreal, Unity or Godot are optimized for running any kind of game people can come up with. But a one-size-fits-all solution often has problems with handling unusual edge cases. When your game is such an unusual edge case, then you might have to create your own engine in order to perform the low-level optimizations you need in order to run your game with satisfying performance.

A couple games which would not have been possible (or at least very difficult) with a general purpose game engine are:

  • Minecraft, with its millions of blocks in a single scene. Which runs so well on low-budget hardware due to the simplistic graphics and well-chosen data-structures.
  • Factorio, which does a lot of micro- and macro-optimization to make sure it can process a huge amount of entities (their development block is a treasure trove of interesting programming tricks).
  • Flappy Bird. Yes, I am serious. What, you say you could do that in your favorite game engine in a couple hours? Sure, but could you squeeze it into an APK of under a MB? Game engines tend to add runtimes which are several MB in size to every game. Which hardly matters for a large project but seems pretty excessive for a tiny one. Filesize is also an important factor for web-based games, where every additional second of loading time will cause you to lose a couple players.

However, game engines do keep developing and become able to cover more specialized use-cases they couldn’t before. Like Unity’s DOTS initiative which allows to create games which require highly optimized game systems and its scriptable render pipelines which can be used to optimize for unusual render performance requirements.

swift – High SpriteKit draw count with SKSpriteNode & texture atlas

I have a SpriteKit game in which there are balls that bounce around. Despite using a texture atlas (a .spriteatlas folder located in my .xcassets folder), I’m getting 2 draw calls for each ball.

Some facts:

  1. The balls are SKSpriteNode‘s.
  2. Each ball is a parent node that has a child node (an overlay with the opposite rotation of the ball to provide the illusion of lighting/shadow). So, we’re talking about 2 nodes for each ball.
  3. The balls’ textures are preloaded up front and stored in memory via textureNamed(_:).
  4. I have set view.ignoresSiblingOrder = true.
  5. There is no SpriteKit background image that would make the balls render on top of another node; the background is transparent. So, the balls do not overlap other content.
  6. zPosition is not set — not on the parent and not on the child.

Based on what I’ve learned about how the scene is rendered, I would expect to see all the parent nodes rendered in a single pass, with additional passes for the child nodes (though, even that is suspicious since I have ignoresSiblingOrder set to true).

What am I not understanding, here? Why does my draw count increase so drastically as more balls are added to the scene?

Thank you!

swift – Drawable presented late, causes steady state delay

I have a little Swift playground that uses a Metal compute kernel to draw into a texture each time the mouse moves. The compute kernel runs very fast, but for some reason, as I start dragging the mouse, some unknown delays build up in the system and eventually the result of each mouse move event is displayed as much as 4 frames after the event is received.

All my code is here: https://github.com/jtbandes/metalbrot-playground

I copied this code into a sample app and added some os_signposts around the mouse event handler so I could analyze it in Instruments. What I see is that the first mouse drag event completes its compute work quickly, but the “surface queued” event doesn’t happen until more than a frame later. Then once the surface is queued, it doesn’t actually get displayed at the next vsync, but the one after that.

The second mouse drag event’s surface gets queued immediately after the compute finishes, but it’s now stuck waiting for another vsync because the previous frame was late. After a few frames, the delay builds and later frames have to wait a long time for a drawable to be available before they can do any work. In the steady state, I see about 4 frames of delay between the event handler and when the drawable is finally presented.

  1. What causes these initial delays and can I do something to reduce them?
  2. Is there an easy way to prevent the delays from compounding, for example by telling the system to automatically drop frames?

swift – URLSession shared – memory leak

I have a scheduled timer requesting a url every x seconds. For some reason URLSession.shared fills the memory slowly over time and never frees it. Anyone an idea why this is happening?

import Foundation

DispatchQueue.global(qos: .default).async {
    let url = URL(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c2/Italian_States-Piacenza_1626_2_Doppie.jpg/2880px-Italian_States-Piacenza_1626_2_Doppie.jpg")!
    Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { timer in
        URLSession.shared.dataTask(with: url) { _, _, _ in


Do we need to have a default clause in a compound switch statement in swift?

I run this swift code:

var planet = "Earth" 
switch planet {
  case "Earth", "Mercury", "Venus", "Mars":
    print("Terrestrial planet")
  case "Saturn", "Jupiter", "Uranus", "Neptune":
    print("Jovian planet")
    print("Unknown planet")

It runs perfectly.
But when I run this:

var planet = "Earth" 

switch planet {
  case "Earth", "Mercury", "Venus", "Mars":
    print("Terrestrial planet")
  case "Saturn", "Jupiter", "Uranus", "Neptune":
    print("Jovian planet")

I get this error:

Planets.swift:4:1: error: switch must be exhaustive
switch planet {
Planets.swift:4:1: note: do you want to add a default clause?
switch planet {

So does the switch require a default case?
I tried the same without a compound, and it works.

swift – How do I check if the same item exist in plist and SpriteKit?

I am trying to make a RPG game in IOS, with a similar dialogue system in Baldurs Gate. I have created two arrays in a plist file. Like this:

Plist file

As you can see I have two arrays: PlayerMessage; a list (it will be) of multiple choices that the player can touch and NPCMessages; the text that is displayed when the PlayerMessage is touched

I am at the stage where I can touch on the NPC and see a black box with text from array (PlayerMessage). However I do not know how to tell Swift, if a player touches the string of the Item in PlayerMessage and if same item exist in NPC Message display the string of that item.

Here is the code that I have used:

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
    for touch in (touches) {
        NPC.name = "NPC"
        let Location = touch.location(in: self)
                    var CorrectedLocation = CGPoint()
                    CorrectedLocation.x = Location.x - LocalCamera.position.x
                    CorrectedLocation.y = Location.y - LocalCamera.position.y

        let node = self.atPoint(CorrectedLocation)
        var Message: SKLabelNode!
        Message = SKLabelNode(fontNamed: "Trebuchet MS")

        if (node.name == "NPC") {
            let NPCMessageer = SKSpriteNode (color: UIColor.black, size: CGSize(width:1000, height:1000))
            NPCMessageer.zPosition = 99
            NPCMessageer.position = CGPoint(x:-500, y:-200)
          Message.fontSize = 50
            Message.color = UIColor.white;            Message.position = CGPoint(x:-500, y:-100)
            Message.zPosition = 100

            for PlayerMessage in NPC.PlayerMessage {
             Message.text = PlayerMessage as?String}
            let label = self.atPoint(CorrectedLocation)
            if label.name == "Message"
             if NPC.PlayerMessage == NPC.NPCMessage
                Message.text = NPC.NPCMessage as?String

swift – MacOS – Cocoa – Generating Thumbnail with Background template

When using QLThumbnailGenerator.shared.generateRepresentations I’m not able to retry the image preview thumbnail with the white padding (for image cases) like Finder does.

I’m able to retrive just the image its self without the background. This is how Finder renders icon for for text files, the folding paper corner and the contents of the file

enter image description here

Can you tell me please what I’m doing wrong?

This is how finder looks like for image.

enter image description here


strings – Is there a shorter/better way to do this simple problem in Swift?

I am learning swift and then I came across this problem.
Converting each start letter to capitalized form if its lowercased.

func upperCaseFirstCharacter(str:String){
    let myArr = str.components(separatedBy: " ")
    var finalStr :String=""
    for word in myArr {
        let myStr = word.replacingCharacters(in: ...str.startIndex, with: word.first?.uppercased() ?? "")
        if myArr.last != word{
            finalStr.append(" ")

How to make Horizontal scroll segment in swift

when we scroll segment horizontally then the segment and regarding viewcontroller should scroll move horizontally

for that i have tried SJSegmentedScrollView

i have installed cocoapod and added below code:

code: but here even segment not coming.. where i am mistake.. how to add segment and viewcontrollers horizontally

or is there any other thirdparty library for segment please do help here

import UIKit
import SJSegmentedScrollView

class SegmentViewController: UIViewController {

override func viewDidLoad() {

    // Do any additional setup after loading the view.
    self.navigationController?.isNavigationBarHidden = true
    if let storyboard = self.storyboard {

    let headerViewController = storyboard
        .instantiateViewController(withIdentifier: "SegmentViewController")

    let firstViewController = storyboard
        .instantiateViewController(withIdentifier: "FirstTableViewController")
    firstViewController.title = "First"

    let secondViewController = storyboard
        .instantiateViewController(withIdentifier: "SecondTableViewController")
    secondViewController.title = "Second"

    let thirdViewController = storyboard
        .instantiateViewController(withIdentifier: "ThirdTableViewController")
    thirdViewController.title = "Third"
        self.present(thirdViewController, animated: false, completion: nil)
        let segmentedViewController = SJSegmentedViewController(headerViewController: headerViewController,
        segmentControllers: (firstViewController,
            segmentedViewController.view.frame = self.view.bounds
            segmentedViewController.didMove(toParent: self)