GameplayKit

RSS for tag

Architect and organize your game logic and incorporate common gameplay behaviors in your app using GameplayKit.

Posts under GameplayKit tag

14 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

GameplayKit usage with Swift 6: Call to main actor-isolated instance method 'run' in a synchronous nonisolated context
Hi there, With a couple of other developers we have been busy with migrating our SpriteKit games and frameworks to Swift 6. There is one issue we are unable to resolve, and this involves the interaction between SpriteKit and GameplayKit. There is a very small demo repo created that clearly demonstrates the issue. It can be found here: https://github.com/AchrafKassioui/GameplayKitExplorer/blob/main/GameplayKitExplorer/Basic.swift The relevant code also pasted here: import SwiftUI import SpriteKit struct BasicView: View { var body: some View { SpriteView(scene: BasicScene()) .ignoresSafeArea() } } #Preview { BasicView() } class BasicScene: SKScene { override func didMove(to view: SKView) { size = view.bounds.size anchorPoint = CGPoint(x: 0.5, y: 0.5) backgroundColor = .gray view.isMultipleTouchEnabled = true let entity = BasicEntity(color: .systemYellow, size: CGSize(width: 100, height: 100)) if let renderComponent = entity.component(ofType: BasicRenderComponent.self) { addChild(renderComponent.sprite) } } } @MainActor class BasicEntity: GKEntity { init(color: SKColor, size: CGSize) { super.init() let renderComponent = BasicRenderComponent(color: color, size: size) addComponent(renderComponent) let animationComponent = BasicAnimationComponent() addComponent(animationComponent) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } @MainActor class BasicRenderComponent: GKComponent { let sprite: SKSpriteNode init(color: SKColor, size: CGSize) { self.sprite = SKSpriteNode(texture: nil, color: color, size: size) super.init() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } class BasicAnimationComponent: GKComponent { let action1 = SKAction.scale(to: 1.3, duration: 0.07) let action2 = SKAction.scale(to: 1, duration: 0.15) override init() { super.init() } override func didAddToEntity() { if let renderComponent = entity?.component(ofType: BasicRenderComponent.self) { renderComponent.sprite.run(SKAction.repeatForever(SKAction.sequence([action1, action2]))) } } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } As SKNode is designed to run on the MainActor, the BasicRenderComponent is attributed with MainActor as well. This is needed as this GKComponent is dedicated to encapsulate the node that is rendered to the scene. There is also a BasicAnimationComponent, this GKComponent is responsible for animating the rendered node. Obviously, this is just an example, but when using GameplayKit in combination with SpriteKit it is very common that a GKComponent instance manipulates an SKNode referenced from another GKComponent instance, often done via open func update(deltaTime seconds: TimeInterval) or as in this example, inside didAddToEntity. Now, the problem is that in the above example (but the same goes foupdate(deltaTime seconds: TimeInterval) the methoddidAddToEntity is not isolated to the MainActor, as GKComponent is not either. This leads to the error Call to main actor-isolated instance method 'run' in a synchronous nonisolated context, as indeed the compiler can not infer that didAddToEntity is isolated to the MainActor. Marking BasicAnimationComponent as @MainActor does not help, as this isolation is not propogated back to the superclass inherited methods. In fact, we tried a plethora of other options, but none resolved this issue. How should we proceed with this? As of now, this is really holding us back migrating to Swift 6. Hope someone is able to help out here!
2
2
366
2w
Xcode Error in Scene Editor and Entity/Component Architecture
Hello, I'm writing to report an issue (or a documentation error). I am using the Entity/Component Architecture incorporated in the GamePlayKit framework. Additionally, I want to take advantage of the user interface provided by the Scene Editor. This is essential for me if I want to involve more people in the project. The issue occurs when linking the user interface data with the GKScene of the aforementioned framework. The first issue arises when adding a component through the interface as shown in the image Then at that moment: if let scene = GKScene(fileNamed: "GameScene") { // Get the SKScene from the loaded GKScene if let sceneNode = scene.rootNode as! GameScene? { Scene.rootNode is nil, and the scene is not presented. However, I can work around this issue by initializing the scene separately: if let scene = GKScene(fileNamed: "GameScene") { // Get the SKScene loaded separately if let sceneNode = SKScene(fileNamed: "GameScene") as! GameScene? { But from here, two issues arise: The node contains a component, and the scene has been loaded separately When trying to access a specific entity through its SKSpriteNode: self.node?.entity // Is nil It becomes very difficult to access a specific entity. When adding a component, an entity is automatically created. This is demonstrated here: The node contains a component, and the scene has been loaded separately. I only have one way to access this entity, and since there is only one, it's easy: sceneNode.entities[0] But even so, it's not very useful because when I try to access its components, it turns out they don't exist. I just wanted to mention this because it would be very helpful for me if this issue could be resolved. Thank you very much in advance.
0
0
339
Aug ’24
Camera control in an immersive environment
Hello, I’m playing around with making an fully immersive multiplayer, air to air dogfighting game, but I’m having trouble figuring out how to attach a camera to an entity. I have a plane that’s controlled with a GamePad. And I want the camera’s position to be pinned to that entity as it moves about space, while maintaining the users ability to look around. Is this possible? -- From my understanding, the current state of SceneKit, ARKit, and RealityKit is a bit confusing with what can and can not be done. SceneKit Full control of the camera Not sure if it can use RealityKits ECS system. 2D Window. - Missing full immersion. ARKit Full control of the camera* - but only for non Vision Pro devices. Since Vision OS doesn't have a ARView. Has RealityKits ECS system 2D Window. - Missing full immersion. RealityKit Camera is pinned to the device's position and orientation Has RealityKits ECS system Allows full immersion
0
1
389
Aug ’24
Game Center Notifications do not include GKMessageImage.png
Hello, Asking the following as, I was unable to find answers via search on the forum and in the documentation: Invitations sent via iMessage seem to work correctly with my custom image ( GKMessageImage.png ) however, notifications sent to Game Center Friends via invites generated in Game Center do not include the custom image ( GKMessageImage.png ). Questions: Is this expected behavior? Is there a different way to customize the image in the notification? Note the Game Center notification includes the App name correctly. I also noted in the WWDC session in 2016 ( saw video recently ) that there was some mention of no longer adding friends via Game Center. Is that currently true? Thanks in advance.
1
0
517
Sep ’24
iPhone and iPad Collaboration
Hello, I'm building apps for iPhone and iPad. Those are working together like a 2-screen Nintendo switch. Is there any way for communication between iPhone and iPad without an outside server? PAN(personal area network) could be a solution, but I could not find any information to use it for my case. If the iPad is connected to iPhone as a personal hotspot (though there's no cell tower), they should be communicate each other. I think there's a better way for my case. Could anyone can tell me where I start to looking for? Thanks, JJ
1
0
560
Jun ’24
Error: apple/apple/game-porting-toolkit 1.1 did not build
I was trying update gptk, so i removed the old one ( installed by Xcode 15.0 ) and reinstalled it, but accuired a issue: Error: apple/apple/game-porting-toolkit 1.1 did not build Logs: /Users/CASEM/Library/Logs/Homebrew/game-porting-toolkit/00.options.out /Users/CASEM/Library/Logs/Homebrew/game-porting-toolkit/01.configure /Users/CASEM/Library/Logs/Homebrew/game-porting-toolkit/01.configure.cc /Users/CASEM/Library/Logs/Homebrew/game-porting-toolkit/02.make /Users/CASEM/Library/Logs/Homebrew/game-porting-toolkit/wine64-build If reporting this issue please do so to (not Homebrew/brew or Homebrew/homebrew-core): apple/apple Error: Your Xcode (15.0) is outdated. Please update to Xcode 15.4 (or delete it). Xcode can be updated from the App Store. So I upgrade the Xcode to 15.4 by app store and still encountered: Error: apple/apple/game-porting-toolkit 1.1 did not build Logs: /Users/CASEM/Library/Logs/Homebrew/game-porting-toolkit/00.options.out /Users/CASEM/Library/Logs/Homebrew/game-porting-toolkit/01.configure /Users/CASEM/Library/Logs/Homebrew/game-porting-toolkit/01.configure.cc /Users/CASEM/Library/Logs/Homebrew/game-porting-toolkit/02.make /Users/CASEM/Library/Logs/Homebrew/game-porting-toolkit/wine64-build If reporting this issue please do so to (not Homebrew/brew or Homebrew/homebrew-core): apple/apple I've been reading some post says use 15.1, but still get same error report. What should I do next? Any help woulbe appreciated.
0
0
988
Jun ’24
apple/apple/game-porting-toolkit 1.1 did not build
My MacBook Pro is M3 max, running macOS 14.4.1 (23E224), with Xcode 15.3 and Command_Line_Tools_for_Xcode_15.3 installed. When I tried to execute "brew -v install apple/apple/game-porting-toolkit", it reported the following error. Error: apple/apple/game-porting-toolkit 1.1 did not build Logs: /Users/yuanmouren/Library/Logs/Homebrew/game-porting-toolkit/00.options.out /Users/yuanmouren/Library/Logs/Homebrew/game-porting-toolkit/01.configure /Users/yuanmouren/Library/Logs/Homebrew/game-porting-toolkit/01.configure.cc /Users/yuanmouren/Library/Logs/Homebrew/game-porting-toolkit/02.make /Users/yuanmouren/Library/Logs/Homebrew/game-porting-toolkit/wine64-build If reporting this issue please do so to (not Homebrew/brew or Homebrew/homebrew-core): apple/apple I found the following error reasons in the console. /private/tmp/game-porting-toolkit-20240414-2133-st99bv/wine/dlls/crypt32/unixlib.c:629:11: error: unknown type name 'SecTrustSettingsDomain' const SecTrustSettingsDomain domains[] = { ^ /private/tmp/game-porting-toolkit-20240414-2133-st99bv/wine/dlls/crypt32/unixlib.c:630:9: error: use of undeclared identifier 'kSecTrustSettingsDomainSystem' kSecTrustSettingsDomainSystem, ^ /private/tmp/game-porting-toolkit-20240414-2133-st99bv/wine/dlls/crypt32/unixlib.c:631:9: error: use of undeclared identifier 'kSecTrustSettingsDomainAdmin' kSecTrustSettingsDomainAdmin, ^ /private/tmp/game-porting-toolkit-20240414-2133-st99bv/wine/dlls/crypt32/unixlib.c:632:9: error: use of undeclared identifier 'kSecTrustSettingsDomainUser' kSecTrustSettingsDomainUser ^ /private/tmp/game-porting-toolkit-20240414-2133-st99bv/wine/dlls/crypt32/unixlib.c:640:18: warning: this function declaration is not a prototype [-Wstrict-prototypes] status = SecTrustSettingsCopyCertificates(domains[domain], &certs); ^ /private/tmp/game-porting-toolkit-20240414-2133-st99bv/wine/dlls/crypt32/unixlib.c:641:23: error: use of undeclared identifier 'noErr' if (status == noErr) ^ /private/tmp/game-porting-toolkit-20240414-2133-st99bv/wine/dlls/crypt32/unixlib.c:647:31: warning: this function declaration is not a prototype [-Wstrict-prototypes] if ((status = SecItemExport(cert, kSecFormatX509Cert, 0, NULL, &certData)) == noErr) ^ /private/tmp/game-porting-toolkit-20240414-2133-st99bv/wine/dlls/crypt32/unixlib.c:647:51: error: use of undeclared identifier 'kSecFormatX509Cert' if ((status = SecItemExport(cert, kSecFormatX509Cert, 0, NULL, &certData)) == noErr) ^ /private/tmp/game-porting-toolkit-20240414-2133-st99bv/wine/dlls/crypt32/unixlib.c:647:95: error: use of undeclared identifier 'noErr' if ((status = SecItemExport(cert, kSecFormatX509Cert, 0, NULL, &certData)) == noErr) ^ 2 warnings and 7 errors generated. make: *** [dlls/crypt32/unixlib.o] Error 1 make: *** Waiting for unfinished jobs.... How should I resolve this issue?
4
1
3.1k
Apr ’24
What happened to WWDC 2016 session 608?
I know I watched this but it is no where to be found on Apple's site or the Developer app. Nor does the Wayback Machine have it. http://developer.apple.com/wwdc16/608 Graphics and Games #WWDC16 What’s New in GameplayKit Session 608 Bruno Sommer Game Technologies Engineer Sri Nair Game Technologies Engineer Michael Brennan Game Technologies Engineer
1
1
596
Feb ’24
DS4macOS Compiled Things Partially and Run But it Has 30+ Yellow Warnings & Doesn't Show the Setting
Hi Apple and Swift friends. I'm not really a fluent Swift programmer (or any language) just knowledgable, I just a vague logic of what's going on. This is a gamepad controller remapper similar to DS4Windows on the PC and DSX on Steam gaming. On macOS Sonoma, it successfully compiled and connected the amazing Sony Playstation DualSense but because it has 33 yellow warning, the Setting doesn't show. It says something about outdated something and needs to be replaced by a newer framework.network. It also says it can't use self: It should look like these: What could be the syntax changes that won't produce the 30+ yellow warnings? The file can be had here: [https://github.com/marcowindt/ds4macos) God bless.
0
0
836
Feb ’24
Game Porting Toolkit Error
I tried twice to install homebrew and I got a error message twice: Error: apple/apple/game-porting-toolkit 1.1 did not build Logs: /Users/omarzunun/Library/Logs/Homebrew/game-porting-toolkit/00.options.out /Users/omarzunun/Library/Logs/Homebrew/game-porting-toolkit/01.configure /Users/omarzunun/Library/Logs/Homebrew/game-porting-toolkit/01.configure.cc /Users/omarzunun/Library/Logs/Homebrew/game-porting-toolkit/02.make /Users/omarzunun/Library/Logs/Homebrew/game-porting-toolkit/wine64-build If reporting this issue please do so to (not Homebrew/brew or Homebrew/homebrew-core): apple/apple
1
1
1.9k
Jan ’24
Game Center MatchMaker only work on WIFI
I'm working in a game where I integrate matchmaker and it's working fine when I try with two devices under same wifi network, but in the moment I use 5g mobile network and I do the matchmaker, I can still see each other but the game did not start and I see error sending data to the remote player. The game is not yet published and I'm using TestFlight for the clients.
0
0
599
Jan ’24
GameKit - iCloud Sign In Error
Hi everyone, I'm trying to implement matchmaking in visionOS using GameKit and GameCenter. I'm following the example project that been shared but I get an error. Error: The requested operation could not be completed because you are not signed in to iCloud.. I'm getting this error as a result of matchmaking. I'm already logged in to iCloud in Vision Pro Simulator. I've tried to switch off-on every related settings but didn't work. I'm using latest Xcode Dev Beta and visionOS Beta v6. Would you mind share me any workaround? Regards, Melih
3
0
1.1k
Jan ’24