@preeternal/react-native-godot 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,146 +4,146 @@
4
4
  [![npm downloads](https://img.shields.io/npm/dm/@preeternal/react-native-godot.svg)](https://www.npmjs.com/package/@preeternal/react-native-godot)
5
5
  [![Patreon](https://img.shields.io/endpoint?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%2F%3Fusername%3Dpreeternal%26type%3Dpatrons)](https://www.patreon.com/preeternal)
6
6
 
7
- React Native Godot allows embedding the Godot Engine into React Native applications.
7
+ Bring interactive Godot scenes into your React Native app on Android and iOS.
8
+ Build animated 3D previews, product viewers, interactive diagrams or small games
9
+ alongside your existing screens and navigation.
8
10
 
9
- Preeternal React Native Godot is a maintained fork of the original React Native Godot integration.
11
+ Author scenes and animations in Godot, then control them from TypeScript or
12
+ JavaScript. React Native handles the app UI; Godot renders inside a native view.
10
13
 
11
- ## Upstream / credits
14
+ ## Features
12
15
 
13
- The original implementation — including the native bridge, platform
14
- integration and LibGodot integration — was developed and maintained by
15
- [Migeran](https://migeran.com). Thank you to the Migeran team and contributors
16
- for building the project and its underlying engine integration.
16
+ - Embed the main Godot window and named subwindows in React Native screens.
17
+ - Start, stop and restart the engine with different Godot projects.
18
+ - Pause and resume a running instance.
19
+ - Access Godot objects, methods, properties, signals and Callables from JavaScript.
20
+ - Run Godot and its JavaScript worklets on a dedicated thread.
21
+ - Choose OpenGL Compatibility, Metal on iOS devices, or Vulkan on Android.
22
+ - Use audio playback by default and opt into microphone capture when needed.
17
23
 
18
- [Born](https://born.com) deserves credit for the original [React Native
19
- adaptation](https://github.com/borndotcom/react-native-godot) and early product integration.
24
+ ## Versions
20
25
 
21
- This fork is currently used in my own project. Long-term maintenance,
22
- backward compatibility and response times are not guaranteed; support will
23
- depend on my needs and available time.
26
+ | Library release | Godot version | Source branch |
27
+ | ------------------------------ | ------------- | ------------------------------------------------------------------------------ |
28
+ | `0.1.0` — previous release | 4.5.1 | [`godot-4.5`](https://github.com/Preeternal/react-native-godot/tree/godot-4.5) |
29
+ | `0.2.0` — this README | 4.7.2 | [`godot-4.7`](https://github.com/Preeternal/react-native-godot/tree/godot-4.7) |
24
30
 
25
- ## Main Features
31
+ The 4.7 line is the current development focus. The `godot-4.5` branch is kept
32
+ for possible fixes to the previous line; backports are considered as needed.
26
33
 
27
- * Supports Android and iOS, built on [LibGodot](https://github.com/Preeternal/libgodot).
28
- * Supports starting, stopping and restarting the Godot Engine. [(docs)](#initialize-the-godot-instance)
29
- * When restarting, the engine can be reconfigured, so a different Godot app may be loaded each time. [(docs)](#stop-the-godot-instance)
30
- * It is also possible to pause and resume the running Godot instance. [(docs)](#pause-the-godot-instance)
31
- * Godot is running on a separate thread, so it does not affect the main thread of the application nor the React Native JavaScript thread. [(docs)](#threading-and-javascript-in-react-native)
32
- * The Godot main window and any subwindows created by the Godot app may be embedded into the React Native application either on the same screen, or on separate screens (see [example app](example/)).
33
- * The whole Godot API is accessible from TypeScript / JavaScript. It is possible to instantiate objects, call methods, get and set properties, attach JS functions to signals, provide JS functions as callables to Godot methods ... etc. [(docs)](#godot-api-usage)
34
+ ## Compatibility
34
35
 
35
- ## Getting Started with the Example App
36
+ | Requirement | Supported configuration |
37
+ | ------------ | ------------------------------------------------------------------- |
38
+ | React Native | New Architecture |
39
+ | Worklets | Version satisfying this package's [peer dependencies](package.json) |
40
+ | iOS | 15.0 or newer |
41
+ | Android | Android 10 / API 29 or newer; `arm64-v8a` and `armeabi-v7a` |
42
+ | Expo | Development Builds; Expo Go cannot load this native module |
36
43
 
37
- The [example app](example/) shows the main features of React Native Godot in action.
44
+ The library includes a pinned engine; you do not need to build Godot yourself.
45
+ This branch uses
46
+ [LibGodot `4.7.2.preeternal.2`](https://github.com/Preeternal/libgodot/releases/tag/4.7.2.preeternal.2),
47
+ based on Godot 4.7.2. Export your Godot content with a compatible editor.
38
48
 
39
- ## Install prerequisites
49
+ ## Installation
40
50
 
41
- During development this repository uses [ASDF](https://asdf-vm.com/) for the
42
- Node.js, Java and Ruby versions recorded in `.tool-versions`. ASDF is optional;
43
- you may install the React Native prerequisites with any supported toolchain.
44
- If you use ASDF, run:
51
+ Install the library and its Worklets dependency:
45
52
 
46
53
  ```sh
47
- asdf install
54
+ yarn add @preeternal/react-native-godot react-native-worklets
48
55
  ```
49
56
 
50
- This installs the versions used in our development environment. Otherwise you
51
- may install the React Native prerequisites using any supported method.
52
-
53
- ## Export the Godot app
54
-
55
- Run the following scripts for either platform you plan to test (or both):
57
+ Or with npm:
56
58
 
57
59
  ```sh
58
- cd example
59
- ./export_godot_GodotTest.sh android
60
- ./export_godot_GodotTest.sh ios
61
- ./export_godot_GodotTest2.sh android
62
- ./export_godot_GodotTest2.sh ios
60
+ npm install @preeternal/react-native-godot react-native-worklets
63
61
  ```
64
62
 
65
- The script is configured to look for Godot in the standard system wide installation folder on macOS. If your Godot is installed elsewhere, or you are on Linux, just point the `GODOT_EDITOR`
66
- environment variable to your Godot editor prior to running the above scripts:
63
+ React Native autolinks the native module. Installation downloads the pinned
64
+ LibGodot binaries from GitHub and verifies archive checksums. Allow the package's
65
+ install script if your package manager requires script approval.
66
+
67
+ If the automatic download did not run or failed, retry it from your app directory:
67
68
 
68
69
  ```sh
69
- export GODOT_EDITOR=/path/to/godot_editor
70
+ node node_modules/@preeternal/react-native-godot/scripts/download-prebuilt.js
70
71
  ```
71
72
 
72
- ## Install dependencies and LibGodot
73
+ This downloads missing engine packages and verifies their checksums. Then retry
74
+ your native dependency installation or build.
73
75
 
74
- ```sh
75
- yarn
76
+ Add the Worklets plugin last in your application's Babel plugins:
77
+
78
+ ```js
79
+ module.exports = {
80
+ presets: ['module:@react-native/babel-preset'],
81
+ plugins: ['react-native-worklets/plugin'],
82
+ };
76
83
  ```
77
84
 
78
- Installing the dependencies also downloads the prebuilt LibGodot release from GitHub. Existing prebuilt files are reused on subsequent installs.
85
+ In an Expo app, keep the `babel-preset-expo` preset.
86
+
87
+ ### iOS: CocoaPods (default)
79
88
 
80
- ## Run on the iOS Simulator
89
+ From your app directory:
81
90
 
82
91
  ```sh
83
- cd example
84
- bundle install
85
92
  cd ios
86
93
  bundle exec pod install
87
94
  cd ..
88
- cd ..
89
- yarn ios
90
95
  ```
91
96
 
92
- ## Run on the Android Emulator
97
+ Rebuild the native app after installation.
93
98
 
94
- ```sh
95
- yarn android
96
- ```
97
-
98
- ## Use your native IDEs
99
-
100
- You may use Xcode and Android Studio the same way as with any other project. Just open:
99
+ ### iOS: Swift Package Manager (React Native 0.87+)
101
100
 
102
- * ``ios/RTNGodotViewExample.xcworkspace`` from Xcode
103
- * ``android`` from Android Studio
101
+ SwiftPM is an experimental, opt-in alternative to CocoaPods. Every native
102
+ dependency, including Worklets, must provide a compatible SwiftPM manifest.
104
103
 
105
- > [!note]
106
- > If you are using ASDF to manage your Java and Node dependencies, you should start Android Studio from under the `react-native-godot` (or `example`) folder, so it can find these tools. For example on macOS:
104
+ To migrate your app once:
107
105
 
108
106
  ```sh
109
- cd example
110
- open -a "Android Studio"
107
+ cd ios
108
+ npx react-native spm --deintegrate
111
109
  ```
112
110
 
113
- ## Convenience script for dependency management
114
-
115
- There is an `update_deps.sh` script included in the example app's folder. It will execute all the setup commands for both iOS and Android in one step, so you may start your work immediately.
111
+ After a fresh clone or a dependency change, generate the SwiftPM workspace
112
+ from your app's `ios` directory:
116
113
 
117
114
  ```sh
118
- cd example
119
- ./update_deps.sh
120
- yarn ios # or yarn android
115
+ npx react-native spm
121
116
  ```
122
117
 
123
- ## Your first React Native Godot App
118
+ Use React Native's generated workspace; this library's manifest depends on
119
+ React Native's generated headers and codegen products.
124
120
 
125
- This fork is being prepared for its first npm release under
126
- `@preeternal/react-native-godot`. The installation commands below describe the
127
- intended published package.
121
+ ### Android
128
122
 
129
- Just follow these steps to add it to your React Native application:
123
+ In a Community CLI app, set `minSdkVersion` to at least `29` in
124
+ `android/build.gradle`:
130
125
 
131
- ## Compatibility
132
-
133
- The example is a React Native Community CLI project aligned with React Native 0.88.0 and React 19.3.0. It uses the New Architecture, Hermes, Kotlin on Android, Swift app entrypoints on iOS, and `react-native-worklets` for Godot-thread calls.
126
+ ```groovy
127
+ buildscript {
128
+ ext {
129
+ minSdkVersion = 29
130
+ }
131
+ }
132
+ ```
134
133
 
135
- On iOS, `RTNGodotView` initializes Fabric's `_props` with generated `RTNGodotViewProps` defaults before the first prop update, matching the Fabric contract used by React Native 0.88.
134
+ Keep your other existing build settings. Set the supported architectures in
135
+ `android/gradle.properties`:
136
136
 
137
- The Android integration requires Android 10 (API 29) because window embedding uses `SurfaceControl`. The bundled Godot binaries currently support `armeabi-v7a` and `arm64-v8a`; the example restricts `reactNativeArchitectures` to those ABIs so its APK never advertises an x86 variant that cannot load Godot.
137
+ ```properties
138
+ reactNativeArchitectures=armeabi-v7a,arm64-v8a
139
+ ```
138
140
 
139
- ## Expo Dev Builds
141
+ Use an ARM device or ARM emulator. The bundled engine does not contain x86 or
142
+ x86_64 binaries. The library registers its bundled Maven repository automatically.
140
143
 
141
- The package works in bare React Native Community CLI apps and in Expo Dev
142
- Builds (custom native builds). It cannot run in Expo Go because it contains
143
- native Godot code.
144
+ ### Expo Development Builds
144
145
 
145
- Expo projects should register the package config plugin in `app.json` or
146
- `app.config.js`:
146
+ Register the config plugin in `app.json` or `app.config.js`:
147
147
 
148
148
  ```json
149
149
  {
@@ -152,7 +152,7 @@ Expo projects should register the package config plugin in `app.json` or
152
152
  [
153
153
  "@preeternal/react-native-godot",
154
154
  {
155
- "iosPacks": ["./assets/GodotTest.pck", "./assets/GodotTest2.pck"]
155
+ "iosPacks": ["./assets/main.pck"]
156
156
  }
157
157
  ]
158
158
  ]
@@ -160,18 +160,25 @@ Expo projects should register the package config plugin in `app.json` or
160
160
  }
161
161
  ```
162
162
 
163
- The `iosPacks` option is optional. The plugin configures the Android minimum
164
- SDK, supported ARM ABIs, local LibGodot Maven repository and the asset pattern
165
- needed to retain hidden `.godot` resources, including after clean prebuilds. On iOS it
166
- adds the listed PCK files to the Xcode project. Run `npx expo prebuild` after
167
- changing the plugin configuration.
163
+ `iosPacks` is optional. It lists PCK files to add to the iOS app bundle.
164
+ The plugin configures Android's minimum SDK, ARM architectures, Maven repository
165
+ and Godot asset retention. Run `npx expo prebuild` after changing this
166
+ configuration, then rebuild your Development Build.
167
+
168
+ ## Add your Godot project
168
169
 
169
- ## Android Godot assets
170
+ Export your Godot project as content (PCK or ZIP), rather than as a standalone
171
+ application.
170
172
 
171
- When an Android Godot project is bundled as an unpacked directory and started
172
- with `--path`, its exported scenes and imported resources are stored under the
173
- hidden `.godot` directory. Android Gradle Plugin excludes hidden asset paths by
174
- default, so the application module must keep them in the APK:
173
+ - **Android:** extract the exported ZIP into
174
+ `android/app/src/main/assets/main/`, including its hidden `.godot` directory.
175
+ Start the engine with `--path /main`.
176
+ - **iOS:** add `main.pck` to your Xcode app target's Copy Bundle Resources,
177
+ or list it in the Expo plugin's `iosPacks`. Start the engine with
178
+ `--main-pack` and its absolute path in the app bundle.
179
+
180
+ For unpacked Android exports, preserve hidden Godot resources in your app's
181
+ `android/app/build.gradle`:
175
182
 
176
183
  ```groovy
177
184
  android {
@@ -181,449 +188,401 @@ android {
181
188
  }
182
189
  ```
183
190
 
184
- Without this setting Godot may start without its exported `main.scn`; later
185
- access to the scene tree can then fail natively. The setting belongs in the
186
- consuming Community CLI application's `android/app/build.gradle` (the example
187
- already has it). Expo projects receive this configuration from the package
188
- config plugin; no manual changes to generated Gradle files are needed.
189
-
190
- ## Update `package.json`
191
-
192
- ```sh
193
- yarn add @preeternal/react-native-godot @dr.pogodin/react-native-fs react-native-worklets
194
- ```
195
-
196
- For a React Native Community CLI project, the package is autolinked normally. Install CocoaPods after changing native dependencies and keep the Worklets Babel plugin enabled according to the `react-native-worklets` installation guide.
197
-
198
- ## Prebuilt LibGodot packages
199
-
200
- The LibGodot packages used by React Native Godot are not distributed on npm. The package downloads and verifies them automatically during installation.
201
- The current package uses LibGodot `4.5.1.preeternal.1`, based on Godot `4.5.1`.
202
-
203
- To repeat the download manually, for example after setting local LibGodot override paths, run:
204
-
205
- ```sh
206
- yarn download-prebuilt
207
- ```
208
-
209
- This keeps React Native Godot independent from LibGodot releases while still supporting local customized builds.
210
-
211
- The bundled Android LibGodot artifacts currently contain `arm64-v8a` and `armeabi-v7a`. The Gradle module automatically limits its native build to those ABIs. Running the Godot view therefore requires an ARM Android device or ARM emulator.
212
-
213
- ## Import React Native Godot in your App code
191
+ Expo apps receive this setting from the config plugin. Without it, exported
192
+ scenes and imported resources under `.godot` may be missing from the APK.
214
193
 
215
- ```typescript
216
- import { RTNGodot, RTNGodotView, runOnGodotThread } from "@preeternal/react-native-godot";
217
- ```
194
+ You can also load content from an accessible directory or pack downloaded to
195
+ the app's private storage. Pass its path to `createInstance`.
218
196
 
219
- ## Swift Package Manager (React Native 0.87+)
197
+ ## Usage
220
198
 
221
- The package includes the `Package.swift` manifest required by React Native's
222
- experimental opt-in SwiftPM integration. CocoaPods remains the default path.
223
- To enable SwiftPM in a Community CLI app, run:
199
+ The following example uses `MainBundlePath` to locate the iOS pack. Install
200
+ this helper if your app does not already have another way to find the bundle:
224
201
 
225
202
  ```sh
226
- cd ios
227
- npx react-native spm --deintegrate
228
- npx react-native spm
203
+ yarn add @dr.pogodin/react-native-fs
229
204
  ```
230
205
 
231
- The generated React Native package supplies the React headers and codegen
232
- products referenced by this library. SwiftPM support requires iOS 15 or newer;
233
- the manifest is intended to be consumed through React Native's SPM autolinker,
234
- not as a standalone Swift package with independently resolved React headers.
235
- It also depends on the `RNWorklets` product supplied by the installed
236
- `react-native-worklets` package. All native dependencies in the app must have
237
- compatible SwiftPM manifests.
238
-
239
- ## Add the Godot View to your view, e.g.
206
+ Install its native dependencies before rebuilding on iOS.
240
207
 
241
208
  ```tsx
242
- const App = () => {
243
- return (
244
- <View>
245
- <RTNGodotView style={...}/>
246
- </View>
247
- );
248
- };
249
- ```
250
-
251
- If no `windowName` property is specified, that view is for the main window of Godot.
252
-
253
- ## Initialize the Godot instance
254
-
255
- ```typescript
209
+ import { Button, Platform, View } from 'react-native';
256
210
  import { MainBundlePath } from '@dr.pogodin/react-native-fs';
257
-
258
- function initGodot() {
259
- runOnGodotThread(() => {
211
+ import {
212
+ RTNGodot,
213
+ RTNGodotView,
214
+ runOnGodotThread,
215
+ } from '@preeternal/react-native-godot';
216
+
217
+ function startGodot() {
218
+ const args =
219
+ Platform.OS === 'android'
220
+ ? [
221
+ '--path',
222
+ '/main',
223
+ '--rendering-driver',
224
+ 'opengl3',
225
+ '--rendering-method',
226
+ 'gl_compatibility',
227
+ ]
228
+ : ['--main-pack', `${MainBundlePath}/main.pck`];
229
+ args.push('--display-driver', 'embedded');
230
+
231
+ return runOnGodotThread(() => {
260
232
  'worklet';
261
- console.log("Initializing Godot");
262
-
263
- if (Platform.OS === 'android') {
264
- RTNGodot.createInstance([
265
- "--verbose",
266
- "--path", "/main",
267
- "--rendering-driver", "opengl3",
268
- "--rendering-method", "gl_compatibility",
269
- "--display-driver", "embedded"
270
- ]);
271
- } else {
272
- RTNGodot.createInstance([
273
- "--verbose",
274
- "--main-pack", `${MainBundlePath}/main.pck`,
275
- "--rendering-driver", "opengl3",
276
- "--rendering-method", "gl_compatibility",
277
- "--display-driver", "embedded"
278
- ]);
233
+ if (RTNGodot.getInstance() == null) {
234
+ if (RTNGodot.createInstance(args) == null) {
235
+ throw new Error('Godot failed to start. Check the native logs.');
236
+ }
279
237
  }
280
- }
238
+ });
281
239
  }
282
- ```
283
-
284
- A couple of things to note here:
285
-
286
- * The usual Godot command line parameters can be passed to the initialization function.
287
- * It is key to use the "embedded" display driver, which is required to embed Godot into the React Native application.
288
- * It is possible to specify both a directory or a pack file.
289
- * On Android, inside the main package the access of the pack file's contents is much slower than accessing pack files stored in the private area of the application. If the Godot app is stored inside the main package, then it should be stored as a folder of files in the `asset` folder.
290
- * On iOS, there is no such limitation, so we use a pack file there.
291
- * In many cases the best way is to download the Godot apps at runtime, which has many advantages, including:
292
- * Smaller initial application size
293
- * Deliver specialized app builds for different devices
294
- * Update the Godot app without going through the whole app review process
295
240
 
296
- ## Add the Godot initialization to the App component
297
-
298
- ```tsx
299
- const App = () => {
300
- useEffect(() => {
301
- initGodot()
302
- return () => {};
303
- }, []);
241
+ function stopGodot() {
242
+ return runOnGodotThread(() => {
243
+ 'worklet';
244
+ RTNGodot.destroyInstance();
245
+ });
246
+ }
304
247
 
248
+ export default function App() {
305
249
  return (
306
- <View>
307
- <RTNGodotView style={...}/>
250
+ <View style={{ flex: 1 }}>
251
+ <Button
252
+ title="Start"
253
+ onPress={() => {
254
+ startGodot().catch(console.error);
255
+ }}
256
+ />
257
+ <Button
258
+ title="Stop"
259
+ onPress={() => {
260
+ stopGodot().catch(console.error);
261
+ }}
262
+ />
263
+ <RTNGodotView style={{ flex: 1 }} />
308
264
  </View>
309
265
  );
310
- };
311
- ```
312
-
313
- In this Hello World app, we just initialize Godot when the App view is displayed.
314
- Check out the [example app](example/) in this repository for a more elaborate example.
315
-
316
- ## Stop the Godot instance
317
-
318
- To stop a running Godot instance, call `RTNGodot.destroyInstance()` on the Godot thread:
319
-
320
- ```typescript
321
- function destroyGodot() {
322
- runOnGodotThread(() => {
323
- "worklet";
324
- RTNGodot.destroyInstance();
325
- });
326
266
  }
327
267
  ```
328
268
 
329
- > [!note]
330
- > After stopping an instance, you can start a new one by calling `RTNGodot.createInstance` again. The new instance can be started with different parameters including other Godot projects.
269
+ Start is explicit. `RTNGodotView` displays the engine's main window when
270
+ `windowName` is omitted. Give the view a nonzero size. The `embedded` display
271
+ driver is required.
331
272
 
332
- ## Pause the Godot instance
333
-
334
- To pause a running Godot instance, call `RTNGodot.pause()` on the JavaScript main thread:
335
-
336
- ```typescript
337
- RTNGodot.pause();
338
- ```
273
+ Only one engine instance runs at a time. After stopping it, start a new instance
274
+ with the same arguments or a different project. Stop the engine when your app
275
+ no longer needs it; removing a view is not a request to destroy the engine.
339
276
 
340
- This won't shut down the running instance, just halt it's execution until further notice.
277
+ ### Pause and resume
341
278
 
342
- ## Resume the Godot instance
343
-
344
- To resume a paused Godot instance, call `RTNGodot.resume()` on the JavaScript main thread:
279
+ Call these on the main JavaScript thread:
345
280
 
346
281
  ```typescript
282
+ RTNGodot.pause();
347
283
  RTNGodot.resume();
284
+ const paused = RTNGodot.is_paused();
348
285
  ```
349
286
 
350
- ## Export your Godot project
351
-
352
- You may use the usual export functionality of Godot Engine, just make sure to export to PCK or ZIP and not the whole application.
287
+ Pausing keeps the instance alive.
288
+ For previews shown across several screens, reuse the instance and pause it
289
+ when it is idle instead of loading the project on every navigation. Release
290
+ scene references and signal handlers when their consumer goes away.
353
291
 
354
- In the React Native Godot example application an `export_godot.sh` and an associated `export_godot_GodotTest.sh` script is provided, which can make the export process easier.
292
+ ### Named windows
355
293
 
356
- To export your project to iOS or Android, use our included `export_godot.sh` script with the following parameters:
294
+ Create a Godot subwindow with the matching name, then embed it in another view:
357
295
 
358
- ```
359
- --target: Base directory where the project will be exported. Depending on the platform a pck file or a folder will be created here.
360
- --project: The directory of the project that will be exported.
361
- --name: The name of the exported project.
362
- --preset: The export preset to be used.
363
- --platform: The platform to export the project to (iOS or Android).
296
+ ```tsx
297
+ <RTNGodotView style={{ flex: 1 }} windowName="subwindow" />
364
298
  ```
365
299
 
366
- Notes:
300
+ The [example app](example/README.md) demonstrates this with React Navigation.
367
301
 
368
- * Android projects will be exported into project folders while iOS project will be exported as PCK files.
369
- * By default, `export_godot.sh` will look for an official Godot installation under the Applications folder. If your installation is somewhere else or you would like to use a custom Godot build, specify it's location in the `GODOT_EDITOR` environment variable.
302
+ ## Platform notes
370
303
 
371
- ## Godot API Usage
304
+ ### Choosing a renderer
372
305
 
373
- After importing React Native Godot, you can access the Godot API through the `RTNGodot` class.
306
+ OpenGL Compatibility is a useful starting point for embedded previews and broad
307
+ device coverage. Metal and Vulkan make Godot's Mobile renderer available for
308
+ scenes that need its rendering features. Choose for your scene and target
309
+ hardware: a newer graphics API does not automatically make a simple preview
310
+ faster. See Godot's [renderer comparison](https://docs.godotengine.org/en/stable/tutorials/rendering/renderers.html).
374
311
 
375
- ### Get the API entry point
312
+ | Target | Driver / rendering method | When to use it |
313
+ | ------------- | ------------------------------ | --------------------------------------------------------- |
314
+ | Android | `opengl3` / `gl_compatibility` | Starting point; used by the example |
315
+ | Android | `vulkan` / `mobile` | Optional; validate on your target GPUs |
316
+ | iPhone/iPad | `metal` / `mobile` | Native bridge default when renderer arguments are omitted |
317
+ | iPhone/iPad | `opengl3` / `gl_compatibility` | Explicit Compatibility option |
318
+ | iOS Simulator | `opengl3` / `gl_compatibility` | Only packaged option; selected automatically |
376
319
 
377
- To access the Godot API, first call `RTNGodot.API()`:
320
+ Pass the driver and method together in the arguments to `createInstance`,
321
+ alongside your content path and `--display-driver embedded`:
378
322
 
379
323
  ```typescript
380
- let Godot = RTNGodot.API();
381
- ```
324
+ // OpenGL Compatibility on Android or iOS, including Simulator:
325
+ const rendererArgs = [
326
+ '--rendering-driver',
327
+ 'opengl3',
328
+ '--rendering-method',
329
+ 'gl_compatibility',
330
+ ];
331
+
332
+ // Metal / Mobile on a physical iPhone or iPad:
333
+ const metalArgs = [
334
+ '--rendering-driver',
335
+ 'metal',
336
+ '--rendering-method',
337
+ 'mobile',
338
+ ];
339
+
340
+ // Vulkan / Mobile on a compatible Android device:
341
+ const vulkanArgs = [
342
+ '--rendering-driver',
343
+ 'vulkan',
344
+ '--rendering-method',
345
+ 'mobile',
346
+ ];
347
+ ```
348
+
349
+ Select the renderer before starting the engine. The bridge does not implement
350
+ an automatic retry with a different renderer after startup failure. A
351
+ JavaScript error handler cannot recover from a native crash. If you expose a
352
+ renderer preference, keep a way to reset it before the next engine startup.
353
+
354
+ Practical things to check before shipping:
355
+
356
+ - **Lighting and materials:** Compatibility and Mobile can produce different
357
+ lighting, shadows and shader results. Tune the scene for each renderer you
358
+ offer, especially when matching a 3D background to the surrounding app UI.
359
+ - **Android Vulkan:** black background regions, composition artifacts and slow
360
+ first display have been observed on some devices with embedded content.
361
+ Treat Vulkan as an opt-in path and test both inline and fullscreen views;
362
+ the Android version alone does not establish GPU/driver compatibility.
363
+ - **First display:** loading a scene and preparing shaders can cost more than
364
+ showing it again. Compare Release builds on real devices, measuring both
365
+ first use and reuse. Creating an instance offscreen does not guarantee that
366
+ every shader has been prepared. See Godot's [shader compilation guidance](https://docs.godotengine.org/en/stable/tutorials/performance/pipeline_compilations.html).
367
+ - **Simulator:** the package supports ARM64 on Apple silicon, uses OpenGL and
368
+ contains no Metal backend. Explicit Metal requests are rejected before
369
+ engine creation. Device Metal may perform better, but Simulator frame rates
370
+ and visuals do not predict device results; check the actual device.
371
+
372
+ ### Android input
373
+
374
+ The embedded Android view currently forwards touch input. Godot's virtual
375
+ keyboard, hardware keyboard, mouse, gamepad and sensor input, and standalone
376
+ Godot Android plugins are not connected to this embedded path. Use React Native
377
+ controls for interactions requiring those features.
378
+
379
+ ## Audio and microphone
380
+
381
+ **Audio playback is enabled. Microphone capture is excluded from the default
382
+ build.** No configuration is needed for projects that only play sound.
383
+
384
+ Apple can require `NSMicrophoneUsageDescription` when a bundled SDK references
385
+ protected microphone APIs, even if your app never records audio. The default
386
+ LibGodot build removes capture code and its iOS microphone permission API
387
+ references at compile time. Muting audio or disabling input at runtime cannot
388
+ remove those references. See Apple's [protected resource requirements](https://developer.apple.com/documentation/uikit/requesting-access-to-protected-resources).
389
+ Other SDKs in your app may still require their own purpose strings.
390
+
391
+ ### Enable microphone capture
392
+
393
+ Add this top-level setting to **your app's** `package.json`:
382
394
 
383
- ### Access Singletons
384
-
385
- From the entry point, you can get the engine's singletons:
386
-
387
- ```typescript
388
- // Get Godot's Engine singleton.
389
- let Godot = RTNGodot.API();
390
- var engine = Godot.Engine;
395
+ ```json
396
+ {
397
+ "reactNativeGodot": {
398
+ "microphone": true
399
+ }
400
+ }
391
401
  ```
392
402
 
393
- ### Instantiate Objects
394
-
395
- You can instantiate Godot API objects using their defined constructors:
403
+ Then download the selected binaries from your app directory:
396
404
 
397
- ```typescript
398
- var vector = Godot.Vector2();
405
+ ```sh
406
+ node node_modules/@preeternal/react-native-godot/scripts/download-prebuilt.js
399
407
  ```
400
408
 
401
- ### Access properties
409
+ Refresh iOS native dependencies (`bundle exec pod install` in `ios`, or
410
+ `npx react-native spm` for SwiftPM), then rebuild the native app. Expo apps use
411
+ the same `package.json` setting and also need a new native build.
402
412
 
403
- Object properties can be accessed directly:
413
+ This selects recording-capable LibGodot `4.7.2.preeternal.1` instead of the
414
+ default `4.7.2.preeternal.2`, with matching bindings. Both use Godot 4.7.2.
415
+ Set `microphone` to `false` or remove it, then repeat these steps to return to
416
+ the default. This is a native build choice; JavaScript reload cannot change it.
404
417
 
405
- ```typescript
406
- var vector = Godot.Vector2();
407
- vector.x = 1.0;
408
- vector.y = 2.0;
409
- ```
418
+ Configure `NSMicrophoneUsageDescription` on iOS, `RECORD_AUDIO` and runtime
419
+ permission handling on Android, and `audio/driver/enable_input=true` in your
420
+ Godot project. Re-export after changing Godot settings. The library does not
421
+ request microphone permission for you.
410
422
 
411
- ### Call methods
423
+ ### Silent previews and background music
412
424
 
413
- Godot API methods can also be called:
425
+ For visual-only content, select the `Dummy` audio driver in `project.godot`,
426
+ then re-export and rebuild your app:
414
427
 
415
- ```typescript
416
- let Godot = RTNGodot.API();
417
- var engine = Godot.Engine;
428
+ ```ini
429
+ [audio]
418
430
 
419
- // Call Godot API methods:
420
- var sceneTree = engine.get_main_loop();
421
- var root = sceneTree.get_root();
422
- // NOTE: From here you can access nodes of the scene tree and manipulate them from TypeScript.
431
+ driver/driver="Dummy"
432
+ driver/enable_input=false
423
433
  ```
424
434
 
425
- ### Attach to signals
435
+ This disables Godot audio output and input, avoiding its use of the platform
436
+ audio driver when the preview needs no sound. Setting the master volume to
437
+ zero still leaves that driver active. Check music from another app alongside
438
+ your app's own audio session settings. See [Godot's audio driver setting](https://docs.godotengine.org/en/stable/classes/class_projectsettings.html#class-projectsettings-property-audio-driver-driver).
426
439
 
427
- JS functions can be connected to Godot signals:
428
-
429
- ```typescript
430
- let Godot = RTNGodot.API();
440
+ ## Godot API
431
441
 
432
- var button = Godot.Button();
433
- button.set_text("Button");
434
-
435
- button.pressed.connect(function() {
436
- console.log("Button pressed.")
437
- })
438
- ```
439
-
440
- ### Pass JS functions to Godot
441
-
442
- JS functions can be passed to Godot methods to be used as Callables:
443
-
444
- Let's create a custom RNInterface Node, and add it to the Godot project's scene tree. It's GDScript should read:
445
-
446
- ```gdscript
447
- extends Node
448
- class_name RNInterface
449
-
450
- func test_callable(c: Callable) -> void:
451
- c.call("Hello from Godot")
452
- ```
453
-
454
- From TypeScript we may access it with the following code snippet:
442
+ Use `runOnGodotThread` for engine calls and scene-tree access. It returns a
443
+ Promise, so handle errors in your calling code. Obtain the API inside the
444
+ worklet after starting the engine:
455
445
 
456
446
  ```typescript
457
- const Godot = RTNGodot.API();
458
- const engine = Godot.Engine;
459
- const sceneTree = engine.get_main_loop();
460
- const root = sceneTree.get_root();
461
-
462
- const iface = root.find_child("RNInterface", true, false);
463
-
464
- iface.test_callable(function(s: string) {
465
- console.log("Received text from Godot: " + s)
466
- });
447
+ await runOnGodotThread(() => {
448
+ 'worklet';
449
+ if (RTNGodot.getInstance() == null) return;
450
+
451
+ const Godot = RTNGodot.API();
452
+ const vector = Godot.Vector2();
453
+ vector.x = 1;
454
+ vector.y = 2;
455
+
456
+ const sceneTree = Godot.Engine.get_main_loop();
457
+ if (!sceneTree) return;
458
+
459
+ const root = sceneTree.get_root();
460
+ const player = root.find_child('Player', true, false);
461
+ if (player) {
462
+ player.set_position(vector);
463
+ }
464
+ });
467
465
  ```
468
466
 
469
- ### Threading and JavaScript in React Native
470
-
471
- In a React Native app, the main JavaScript thread, where the bulk of the JavaScript code of the application runs is separate from the Android or iOS apps's main thread.
467
+ Singletons are properties such as `Godot.Engine`. Constructors, properties
468
+ and methods follow the Godot API exposed by the bundled engine.
472
469
 
473
- This way the JS Thread's processing does not affect the main application UI. Following the same pattern, the Godot Engine is also running on its own thread that is separate from both the application's and React Native's main JavaScript thread. As JavaScript is single-threaded by design, to be able to communicate with the Godot thread from JavaScript, we use [react-native-worklets](https://docs.swmansion.com/react-native-worklets/), which allows us to run JS code in the Godot thread using worklets.
470
+ ### Signals
474
471
 
475
- Worklets are JavaScript functions designated with a 'worklet' keyword.
472
+ Connect JavaScript functions to Godot signals from a worklet:
476
473
 
477
474
  ```typescript
478
- function worklet() {
479
- 'worklet'
480
- }
475
+ await runOnGodotThread(() => {
476
+ 'worklet';
477
+ if (RTNGodot.getInstance() == null) return;
478
+
479
+ const Godot = RTNGodot.API();
480
+ const sceneTree = Godot.Engine.get_main_loop();
481
+ if (!sceneTree) return;
482
+
483
+ const button = sceneTree.get_root().find_child('Button', true, false);
484
+ if (button) {
485
+ button.pressed.connect(function () {
486
+ console.log('Button pressed');
487
+ });
488
+ }
489
+ });
481
490
  ```
482
491
 
483
- These functions and all their external dependencies are transformed so they can be executed in separate JS contexts associated with separate threads. For more information, refer to the [React Native Worklets documentation](https://docs.swmansion.com/react-native-worklets/).
484
-
485
- React Native Godot provides a helper function called `runOnGodotThread()` which will allow you to execute such _workletized_ JS functions on the Godot thread.
486
-
487
- In general, this is the recommended way of interacting with the Godot Engine, as shown in our example app.
488
-
489
- While it is possible to interact with the Godot Engine directly from the main React Native thread, there are some caveats and it is generally not recommended:
492
+ Callbacks execute in the Godot runtime. Disconnect signal handlers when your
493
+ application no longer needs them.
490
494
 
491
- * From the Godot Engine's view, such invocations will be executed on a "background" thread, which means, that for example the Scene Tree cannot be fully accessed from this thread directly. For more information on how background threads in Godot work, please refer to its [documentation](https://docs.godotengine.org/en/stable/tutorials/performance/thread_safe_apis.html).
495
+ ### Callables
492
496
 
493
- * Godot object references that were obtained in the Main JS thread and in worklets are not interchangeable, because they are associated with separate JS contexts. It is possible to create object references that can work in multiple JS contexts, but these would add runtime overhead and are currently not supported in React Native Godot.
497
+ Godot methods accepting a `Callable` can receive JavaScript functions.
498
+ For example, attach this GDScript to a node named `RNInterface`:
494
499
 
495
- ## Advanced Topics
496
-
497
- ### Using a custom LibGodot build
498
-
499
- 1. To use a custom LibGodot build, you first need to clone the [Preeternal LibGodot project](https://github.com/Preeternal/libgodot), including all its submodules.
500
-
501
- ```sh
502
- git clone --recursive https://github.com/Preeternal/libgodot
503
- ```
504
-
505
- 1. Then build LibGodot from source:
506
-
507
- ```sh
508
- cd libgodot
509
- ./build_prebuilt_release.sh # for release libraries
510
- # OR
511
- ./build_prebuilt_dev.sh # for development libraries
512
- ```
513
-
514
- NOTE: You may comment out the unnecessary lines in the build script if you're only building for one platform.
515
-
516
- At the end of the process, the necessary files will be produced in the `build/prebuilt/release` or the `build/prebuilt/dev` folder.
517
-
518
- 1. Once the build finished, set these environment variables:
519
-
520
- ```sh
521
- export LIBGODOT_XCFRAMEWORK_PATH=path/to/libgodot/build/prebuilt/release or dev/libgodot.xcframework.zip
522
- export LIBGODOT_CPP_XCFRAMEWORK_PATH=path/to/libgodot/build/prebuilt/release or dev/libgodot-cpp.xcframework.zip
523
- export LIBGODOT_ANDROID_PATH=path/to/libgodot/build/prebuilt/release or dev/libgodot-android.zip
524
- export LIBGODOT_CPP_ANDROID_PATH=path/to/libgodot/build/prebuilt/release or dev/godot-cpp-android.zip
525
- export SHASUM_CHECK=false
526
- export REPLACE_EXISTING=true
527
- ```
528
-
529
- These environment variables override the download logic of the download-prebuilt script of `react-native-godot`:
530
-
531
- * Use locally present files instead of the URLs specified in the `package.json` of `react-native-godot`.
532
- * Do not check the provided SHA-256 hash.
533
- * Force replacing the installed library, even if the same version was already installed.
534
-
535
-
536
- 1. Then run the download-prebuilts script to install the custom built libraries:
537
-
538
- ```sh
539
- yarn download-prebuilt
540
- ```
541
-
542
- NOTE: An example usage of this script can be found in our example/update_deps.sh script.
543
-
544
- 1. On Android, if using the development builds, in the `react-native-godot/android/build.gradle` the
545
- following line needs to be updated to include `godot-dev` as the artifactId:
546
-
547
- ```groovy
548
- api "com.migeran.libgodot:godot-debug:${libGodotVersion}-SNAPSHOT"
549
- ```
550
-
551
- ### Debug Native Godot code
552
-
553
- To debug native engine code (C++), you first need to build and install a development version of LibGodot as described above.
554
-
555
- On iOS this allows you to set breakpoints into the Godot Engine itself in Xcode and debug it as easily as your own app.
556
-
557
- Depending on the Xcode version, you might have to open these files separately in Xcode, and then move the editor from the new window into the window your application's Xcode project.
558
-
559
- On Android a couple more steps will be required:
560
-
561
- * In the Android Studio Run/Debug configurations you also need to add a Symbol directory, where `libgodot_android.so` with the included debug symbols is located. One good place is: `path/to/libgodot/godot/platform/android/java/lib/libs/dev/arm64-v8a`.
562
-
563
- * Depending on the Android Studio version, you may have to include the Godot source tree under the Android Studio project to be able to set breakpoints. A way to do this is to create a symbolic link under the React Native Godot library as follows:
500
+ ```gdscript
501
+ extends Node
564
502
 
565
- ```sh
566
- cd /path/to/your/app/node_modules/@preeternal/react-native-godot/android/src/main/cpp
567
- ln -s /path/to/libgodot/godot godot
503
+ func test_callable(callback: Callable) -> void:
504
+ callback.call("Hello from Godot")
568
505
  ```
569
506
 
570
- * Then reimport the project / resync the Gradle project files into Android Studio.
571
-
572
- ### Debugging Godot Projects in the Godot Editor
573
-
574
- #### Android
575
-
576
- 1. For remote debugging, you first need to build and install a development version of LibGodot as described above.
507
+ Call it from the Godot thread:
577
508
 
578
- 1. Then add these 2 extra parameters to your `RTNGodot.createInstance` call:
579
-
580
- ```typescript
581
- '--remote-debug',
582
- 'tcp://127.0.0.1:6007'
583
- ```
584
-
585
- 1. To expose TCP port 6007 on your Android device via TCP port 6007 on your computer, open a terminal and call:
586
-
587
- ```sh
588
- adb reverse tcp:6007 tcp:6007
589
- ```
590
-
591
- NOTE: This needs to be called again every time you disconnect and reconnect your device.
509
+ ```typescript
510
+ await runOnGodotThread(() => {
511
+ 'worklet';
512
+ if (RTNGodot.getInstance() == null) return;
513
+
514
+ const sceneTree = RTNGodot.API().Engine.get_main_loop();
515
+ if (!sceneTree) return;
516
+
517
+ const node = sceneTree.get_root().find_child('RNInterface', true, false);
518
+ if (node) {
519
+ node.test_callable(function (message: string) {
520
+ console.log(message);
521
+ });
522
+ }
523
+ });
524
+ ```
592
525
 
593
- 1. Now you can open your project in the Godot Editor. First enable 'Debug' -> 'Keep Debug Server Open' from the top menu then you can set your breakpoints. You can also set breakpoints while the app is running.
526
+ ### Threading and object lifetime
594
527
 
595
- 1. Once your breakpoints are set, you can start debugging by launching your app from Android Studio.
528
+ Godot runs on a thread separate from the native UI and React Native JavaScript
529
+ threads. `runOnGodotThread` schedules a Worklets function on that thread.
596
530
 
597
- #### iOS
531
+ Godot object references belong to the JavaScript runtime where they were
532
+ obtained. Keep API access and object manipulation inside Godot worklets; do not
533
+ pass Godot objects between the main JavaScript runtime and the Godot runtime.
534
+ After `destroyInstance`, discard references to the previous instance's objects.
598
535
 
599
- 1. For remote debugging, you first need to build and install a development version of LibGodot as described above.
536
+ ## Upgrading from 4.5
600
537
 
601
- 1. Open the Godot Editor, then go to 'godot' -> 'Editor Settings' -> 'Network' -> 'Debug' -> 'Remote Host' and set your Mac's IP address.
538
+ The 4.7 line keeps the `RTNGodot`, `RTNGodotView` and `runOnGodotThread` entry
539
+ points. Upgrade the library, its native engine packages and your exported Godot
540
+ content together:
602
541
 
603
- 1. Also enable 'Debug' -> 'Keep Debug Server Open'.
542
+ 1. Re-export PCK/ZIP content with Godot 4.7.2. Include the re-exported `.godot`
543
+ resources on Android; replace bundled packs and version any downloaded
544
+ content caches so an old export is not reused accidentally.
545
+ 2. Refresh native dependencies and rebuild the app. The library installs its
546
+ matching engine and bindings automatically; keep custom 4.5 binaries out
547
+ of a 4.7 installation. A JavaScript reload is insufficient.
548
+ 3. Review renderer arguments. An iOS device now defaults to Metal/Mobile;
549
+ choose `opengl3` / `gl_compatibility` explicitly to retain Compatibility.
550
+ Check lighting, shaders and the first visible frame on real devices.
551
+ 4. If your app records audio, [enable microphone capture](#enable-microphone-capture)
552
+ and configure permissions. Playback-only apps can use the default build.
553
+ 5. Check Start → Stop → Start, pause/resume, navigation, resize and any named
554
+ windows used by your app. Drop old Godot object references after Stop.
604
555
 
605
- 1. Then add these 2 extra parameters to your `RTNGodot.createInstance` call:
556
+ For an app staying on 4.5, keep its library release and exported content
557
+ together. The `godot-4.5` branch remains separate from the 4.7 line.
558
+ See the [release notes](CHANGELOG.md) for the changes in this migration.
606
559
 
607
- ```typescript
608
- '--remote-debug',
609
- 'tcp://<your_macs_ip_address>:6007'
610
- ```
560
+ ## Examples
611
561
 
612
- 1. Now you can start debugging by launching your app from Xcode. You can set your breakpoints both before running the app or at runtime.
562
+ See the [example app and its setup instructions](example/README.md) for two
563
+ Godot projects, lifecycle controls and a named subwindow.
613
564
 
614
- NOTE: Your Mac and your iOS device must be connected to the same network/router in order to establish the connection.
565
+ ## Contributing
615
566
 
616
- ## Project
567
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, checks,
568
+ custom engine builds, debugging and release tooling.
617
569
 
618
- Issues and pull requests are welcome in the [GitHub repository](https://github.com/Preeternal/react-native-godot).
570
+ Issues and pull requests are welcome in the
571
+ [GitHub repository](https://github.com/Preeternal/react-native-godot).
572
+ See the [code of conduct](CODE_OF_CONDUCT.md).
619
573
 
620
- ## Contributing
574
+ ## Upstream / credits
621
575
 
622
- Contributions are welcome.
576
+ This maintained fork builds on the native bridge, platform integration and
577
+ LibGodot integration developed by [Migeran](https://migeran.com).
578
+ [Born](https://born.com) deserves credit for the original
579
+ [React Native adaptation](https://github.com/borndotcom/react-native-godot)
580
+ and early product integration.
623
581
 
624
- - [Development workflow](CONTRIBUTING.md#development-workflow)
625
- - [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
626
- - [Code of conduct](CODE_OF_CONDUCT.md)
582
+ The fork adds the Godot 4.7 integration, renderer selection, native lifecycle
583
+ and surface handling fixes, and installation tooling described in the
584
+ [release notes](CHANGELOG.md). It is used in an actively developed app;
585
+ maintenance follows practical integration needs and available time.
627
586
 
628
587
  ## License
629
588