### Configure and Download LibGodot Source: https://github.com/borndotcom/react-native-godot/blob/master/README.md Installs project dependencies and downloads prebuilt LibGodot packages. Run these commands within the example directory. ```shell cd example yarn yarn download-prebuilt ``` -------------------------------- ### Install Dependencies with ASDF Source: https://github.com/borndotcom/react-native-godot/blob/master/README.md Installs all project dependencies using ASDF for environment management. Ensure ASDF is installed and configured. ```shell asdf install ``` -------------------------------- ### Run on Android Emulator Source: https://github.com/borndotcom/react-native-godot/blob/master/README.md Starts the React Native application on the Android emulator. Navigate to the example directory before running. ```shell cd example yarn android ``` -------------------------------- ### Complete Android Initialization Example Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/configuration.md An example demonstrating the complete initialization of React Native Godot for Android, including verbose logging, path, rendering drivers, and the embedded display driver. ```typescript import { RTNGodot, runOnGodotThread } from "@borndotcom/react-native-godot"; import { Platform } from "react-native"; function initGodotAndroid() { runOnGodotThread(() => { "worklet"; RTNGodot.createInstance([ "--verbose", "--path", "/main", "--rendering-driver", "opengl3", "--rendering-method", "gl_compatibility", "--display-driver", "embedded", ]); }); } ``` -------------------------------- ### Initialize and Install TurboModule Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/module-architecture.md This snippet shows the initialization process for the RTNGodot singleton during app startup. It retrieves the TurboModule and installs it into the global worklet context. ```typescript const GodotInstaller = TurboModuleRegistry.getEnforcing("NativeGodotModule"); globalThis.__godotWorkletContext = Worklets.createContext("ReactNativeGodot"); GodotInstaller.installTurboModule(); // Returns boolean globalThis.RTNGodot = ; ``` -------------------------------- ### Download Prebuilt Assets Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/README.md Download necessary prebuilt assets for the library. This command should be run after installing the library. ```bash yarn download-prebuilt ``` -------------------------------- ### GodotModuleInterface Usage Example Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/types.md Example of how to import and use the RTNGodot singleton instance to control the Godot Engine. ```typescript import { RTNGodot } from "@borndotcom/react-native-godot"; const instance: GodotModuleInterface = RTNGodot; instance.pause(); instance.resume(); ``` -------------------------------- ### Install Expo Filesystem Source: https://github.com/borndotcom/react-native-godot/blob/master/README.md Install the Expo Filesystem module to easily handle file system paths in React Native. ```sh yarn add expo-file-system ``` -------------------------------- ### Initialize and Start Godot Engine Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/README.md Initializes the Godot Engine instance with platform-specific arguments. This function should be called to set up the engine before rendering. ```typescript import { RTNGodot, runOnGodotThread } from "@borndotcom/react-native-godot"; import { Platform } from "react-native"; import * as FileSystem from "expo-file-system/legacy"; function initGodot() { runOnGodotThread(() => { "worklet"; if (Platform.OS === "android") { RTNGodot.createInstance([ "--verbose", "--path", "/main", "--rendering-driver", "opengl3", "--rendering-method", "gl_compatibility", "--display-driver", "embedded" ]); } else { RTNGodot.createInstance([ "--verbose", "--main-pack", FileSystem.bundleDirectory + "main.pck", "--rendering-driver", "metal", "--rendering-method", "mobile", "--display-driver", "embedded" ]); } }); } ``` -------------------------------- ### Install React Native Godot Library Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/README.md Install the library using yarn. This is the first step in integrating Godot into your React Native project. ```bash yarn add @borndotcom/react-native-godot ``` -------------------------------- ### Rebuild Native Code for iOS Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/README.md After installing the library and downloading prebuilts, rebuild the native code for iOS by installing pods. Ensure you are in the project root. ```bash yarn && cd example/ios && pod install ``` -------------------------------- ### Update Dependencies and Run App Source: https://github.com/borndotcom/react-native-godot/blob/master/README.md A convenience script to set up all dependencies for both iOS and Android. After running, you can start the app using 'yarn ios' or 'yarn android'. ```shell cd example ./update_deps.sh yarn ios # or yarn android ``` -------------------------------- ### Open Android Studio from Project Root Source: https://github.com/borndotcom/react-native-godot/blob/master/README.md Opens Android Studio from the project's example directory to ensure correct environment variable detection. This is useful when using ASDF for Java and Node dependencies. ```shell cd example open -a "Android Studio" ``` -------------------------------- ### Clean Build Cache and Rebuild Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/errors.md This command sequence helps resolve issues with the native module installation by cleaning caches and redownloading prebuilt libraries. It's useful when encountering 'Failed NativeGodotModule.installTurboModule()'. ```bash yarn clean cd example yarn yarn download-prebuilt ``` -------------------------------- ### Run on iOS Simulator Source: https://github.com/borndotcom/react-native-godot/blob/master/README.md Installs Ruby dependencies and runs the React Native application on the iOS simulator. Ensure you are in the example/ios directory for pod installation. ```shell cd example/ios bundle install bundle exec pod install cd .. yarn ios ``` -------------------------------- ### Correct Godot Initialization Arguments Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/errors.md These examples show the correct way to pass command-line arguments to RTNGodot.createInstance, focusing on the required '--display-driver embedded' argument and platform-specific path handling. ```typescript // ❌ WRONG - Will not render RTNGodot.createInstance([ "--path", "/main", "--rendering-driver", "opengl3" ]); // ✅ CORRECT RTNGodot.createInstance([ "--path", "/main", "--rendering-driver", "opengl3", "--rendering-driver", "gl_compatibility", "--display-driver", "embedded" // REQUIRED ]); ``` ```typescript // ❌ WRONG - Asset not found RTNGodot.createInstance([ "--path", "/nonexistent_path", "--display-driver", "embedded" ]); // ✅ CORRECT - Path relative to app private storage or assets RTNGodot.createInstance([ "--path", "/main", // Must exist in assets or private dir "--display-driver", "embedded" ]); ``` ```typescript import * as FileSystem from "expo-file-system/legacy"; // ❌ WRONG - Using --path on iOS RTNGodot.createInstance([ "--path", "/main", "--display-driver", "embedded" ]); // ✅ CORRECT - Use --main-pack on iOS RTNGodot.createInstance([ "--main-pack", FileSystem.bundleDirectory + "main.pck", "--display-driver", "embedded" ]); ``` -------------------------------- ### Production Build Commands for iOS Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/configuration.md Commands to perform a production build for iOS, including dependency installation and Xcode build. ```bash # iOS cd example/ios pod install xcodebuild -configuration Release ``` -------------------------------- ### Rebuild Native Dependencies Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/errors.md Use this command to rebuild native dependencies after installing or updating the react-native-godot package. Ensure you are in the example directory or your project root. ```bash cd example # or your project root yarn download-prebuilt cd ios && pod install && cd .. # iOS # OR cd android && ./gradlew clean && cd .. # Android ``` -------------------------------- ### Responsive Layout with RTNGodotView Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/api-reference/RTNGodotView.md An example showing how to integrate RTNGodotView into a responsive layout, adjusting its height based on the screen dimensions. ```tsx import React from "react"; import { View, StyleSheet, Dimensions } from "react-native"; import { RTNGodotView } from "@borndotcom/react-native-godot"; export function GameScreenWithUI() { const windowHeight = Dimensions.get("window").height; return ( {/* UI controls here */} {/* Bottom controls here */} ); } const styles = StyleSheet.create({ container: { flex: 1, }, header: { height: 50, backgroundColor: "#333", }, godotView: { flex: 1, }, footer: { height: 60, backgroundColor: "#333", }, }); ``` -------------------------------- ### Access the Godot API from a Worklet Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/README.md Provides an example of how to access the Godot API, including singletons, instantiating classes, calling methods, and connecting signals, all from within a worklet context. ```typescript import { RTNGodot, runOnGodotThread } from "@borndotcom/react-native-godot"; async function accessGodotAPI() { await runOnGodotThread(() => { "worklet"; const Godot = RTNGodot.API(); // Access singletons const engine = Godot.Engine; const sceneTree = engine.get_main_loop(); const root = sceneTree.get_root(); // Instantiate classes const vector = Godot.Vector2(); vector.x = 100; vector.y = 200; // Call methods const node = root.get_child(0); node.set_name("MyNode"); // Connect signals const button = Godot.Button(); button.pressed.connect(() => { console.log("Button clicked!"); }); }); } ``` -------------------------------- ### Get Godot API Entry Point Source: https://github.com/borndotcom/react-native-godot/blob/master/README.md Access the Godot API by first calling RTNGodot.API() to get the entry point object. ```typescript let Godot = RTNGodot.API(); ``` -------------------------------- ### Basic Usage of RTNGodotView for Main Window Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/api-reference/RTNGodotView.md A simple example demonstrating how to render the main Godot window using the RTNGodotView component within a React Native view. ```tsx import React from "react"; import { View, StyleSheet } from "react-native"; import { RTNGodotView } from "@borndotcom/react-native-godot"; export function MainGameScreen() { return ( ); } const styles = StyleSheet.create({ container: { flex: 1, }, godotView: { flex: 1, }, }); ``` -------------------------------- ### Check Native Logs for Errors Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/errors.md Use these commands to check detailed native logs for errors during Godot engine initialization or module installation. This is helpful for diagnosing issues on Android and iOS. ```bash # Android adb logcat | grep -i godot # iOS # Check Xcode console output ``` -------------------------------- ### Android NativeGodotModule Implementation Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/module-architecture.md This Java code implements the NativeGodotModule for Android, extending the generated spec and providing a native method for installing the TurboModule. ```java @ReactModule(name = NativeGodotModule.NAME) public class NativeGodotModule extends NativeGodotModuleSpec { @ReactMethod(isBlockingSynchronousMethod = true) @Override public native boolean installTurboModule(); } ``` -------------------------------- ### RTNGodotView Usage Example Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/types.md Example of how to use the RTNGodotView component in a React Native application. The 'windowName' prop corresponds to a Godot window created by the application. ```typescript import { RTNGodotView } from "@borndotcom/react-native-godot"; ``` -------------------------------- ### Using the "worklet" Directive for Thread Execution Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/errors.md This example shows the correct usage of the 'worklet' directive, which is essential for proper transpilation and execution of functions on separate threads. Omitting it can lead to unexpected behavior. ```typescript // ❌ WRONG - Missing "worklet" directive runOnGodotThread(() => { // This may not work correctly RTNGodot.createInstance([...]); }); // ✅ CORRECT runOnGodotThread(() => { "worklet"; // Required magic string RTNGodot.createInstance([...]); }); ``` -------------------------------- ### Configure Prebuilt Library in package.json Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/configuration.md Defines the configuration for prebuilt library downloads within the root package.json. This includes library name, filename, version, download URL, checksum, destination, and environment variable for overriding the download location. ```json { "prebuiltFiles": [ { "name": "libgodot", "filename": "libgodot.xcframework.zip", "version": "4.5.1.migeran.2", "base_url": "https://github.com/migeran/libgodot/releases/download/", "shasum": "699fcc7e3eef7d0aee3132c6ebd7a8a9a7b6b0c9da801d220d72950e4ac79958", "destination_base_dir": "ios/libs", "env": "LIBGODOT_XCFRAMEWORK_PATH", "no_unpack": false } // ... more entries for other platforms ] } ``` -------------------------------- ### RTNGodotView Codegen Example Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/types.md Example of how RTNGodotView is defined using codegenNativeComponent. This creates a typed React component for native integration. ```typescript export default codegenNativeComponent( "RTNGodotView" ) as HostComponent; ``` -------------------------------- ### Development Build Commands Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/configuration.md Common commands for setting up and checking a development build of the project. ```bash yarn install yarn download-prebuilt yarn typecheck yarn lint ``` -------------------------------- ### iOS Path Configuration using .pck File Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/configuration.md On iOS, specify a .pck file using the bundle directory. Always use `--main-pack` for iOS, and ensure the .pck file is in the app bundle. ```typescript import * as FileSystem from "expo-file-system/legacy"; RTNGodot.createInstance([ "--main-pack", FileSystem.bundleDirectory + "main.pck", "--display-driver", "embedded", // ... ]); ``` -------------------------------- ### createInstance Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/api-reference/RTNGodot.md Creates and initializes a new Godot Engine instance with the specified command-line arguments. This function must be called within a worklet context via `runOnGodotThread()`. ```APIDOC ## createInstance(args: string[]) ### Description Creates and initializes a new Godot Engine instance with the specified command-line arguments. This function must be called within a worklet context via `runOnGodotThread()`. ### Method N/A (JSI Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **args** (string[]) - Required - Array of command-line arguments passed to the Godot Engine. Must include `--display-driver embedded` to embed the engine in React Native. Platform-specific paths and rendering driver configurations are specified here. ### Request Example ```typescript import { RTNGodot, runOnGodotThread } from "@borndotcom/react-native-godot"; import * as FileSystem from "expo-file-system/legacy"; import { Platform } from "react-native"; function initGodot() { runOnGodotThread(() => { "worklet"; if (Platform.OS === "android") { RTNGodot.createInstance([ "--verbose", "--path", "/main", "--rendering-driver", "opengl3", "--rendering-method", "gl_compatibility", "--display-driver", "embedded" ]); } else { RTNGodot.createInstance([ "--verbose", "--main-pack", FileSystem.bundleDirectory + "main.pck", "--rendering-driver", "opengl3", "--rendering-method", "gl_compatibility", "--display-driver", "embedded" ]); } }); } ``` ### Response #### Success Response (N/A) Returns the initialized Godot Engine instance object. #### Response Example N/A ``` -------------------------------- ### Spec Interface Definition Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/types.md Internal interface for native TurboModule installation. This is not intended for direct use by application code. ```typescript export interface Spec extends TurboModule { installTurboModule(): boolean; } ``` -------------------------------- ### Access and Modify Godot Object Properties Source: https://github.com/borndotcom/react-native-godot/blob/master/README.md Shows how to access and set properties of a Godot object, using Vector2 as an example. ```typescript var vector = Godot.Vector2(); vector.x = 1.0; vector.y = 2.0; ``` -------------------------------- ### Initialize Godot Instance if Null Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/errors.md Check if the Godot instance is null and initialize it if necessary. This is a common fix for black screen issues. ```typescript if (RTNGodot.getInstance() === null) { console.log("Godot not initialized - calling init"); await initGodot(); } ``` -------------------------------- ### Retrieve Current Godot Engine Instance Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/api-reference/RTNGodot.md Gets the currently running Godot Engine instance. Returns null if no instance is active. ```typescript import { RTNGodot } from "@borndotcom/react-native-godot"; let instance = RTNGodot.getInstance(); if (instance === null) { console.log("No Godot instance is running"); } ``` -------------------------------- ### react-native-builder-bob Configuration Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/configuration.md Configuration for react-native-builder-bob, specifying source, output, and build targets for bundling. ```json { "react-native-builder-bob": { "source": "js", "output": "lib", "targets": [ "commonjs", "module", [ "typescript", { "project": "tsconfig.build.json" } ] ] } } ``` -------------------------------- ### Initialize Subwindow on Mount Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/api-reference/RTNGodotView.md Use useEffect with an empty dependency array to open and close subwindows when the screen mounts and unmounts, especially when using React Navigation. ```tsx useEffect(() => { openSubwindow(); return () => { closeSubwindow(); }; }, []); // Empty array: effect runs once on mount ``` -------------------------------- ### API Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/api-reference/RTNGodot.md Returns the Godot Engine API entry point. This is the root object through which the entire Godot API (Engine singleton, classes, and nodes) is accessed. ```APIDOC ## API() ### Description Returns the Godot Engine API entry point. This is the root object through which the entire Godot API (Engine singleton, classes, and nodes) is accessed. ### Method N/A (JSI Method) ### Endpoint N/A ### Parameters None ### Request Example ```typescript import { RTNGodot, runOnGodotThread } from "@borndotcom/react-native-godot"; runOnGodotThread(() => { "worklet"; const Godot = RTNGodot.API(); // Access Engine singleton const engine = Godot.Engine; // Instantiate Godot classes const vector = Godot.Vector2(); vector.x = 10; vector.y = 20; // Access scene tree const sceneTree = engine.get_main_loop(); const root = sceneTree.get_root(); }); ``` ### Response #### Success Response (N/A) Returns the Godot API object with access to: `Engine`, Godot class constructors, and the scene tree root. #### Response Example N/A ``` -------------------------------- ### Initialize Godot Instance Source: https://github.com/borndotcom/react-native-godot/blob/master/README.md Initialize the Godot instance with specific command-line arguments. Use 'embedded' display driver for React Native integration. Handles platform-specific path configurations for Android and iOS. ```typescript import * as FileSystem from 'expo-file-system/legacy'; function initGodot() { runOnGodotThread(() => { 'worklet'; console.log("Initializing Godot"); if (Platform.OS === 'android') { RTNGodot.createInstance([ "--verbose", "--path", "/main", "--rendering-driver", "opengl3", "--rendering-method", "gl_compatibility", "--display-driver", "embedded" ]); } else { RTNGodot.createInstance([ "--verbose", "--main-pack", FileSystem.bundleDirectory + "main.pck", "--rendering-driver", "opengl3", "--rendering-method", "gl_compatibility", "--display-driver", "embedded" ]); } } } ``` -------------------------------- ### Embed LibGodot Framework on iOS Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/errors.md Ensure `libgodot.xcframework` is correctly embedded in your Xcode project under 'Frameworks, Libraries, and Embedded Content' with 'Embed & Sign'. Run `pod install` after verifying. ```bash cd ios pod install # Verify in Xcode: General tab → Frameworks, Libraries, and Embedded Content # libgodot.xcframework should be listed with "Embed & Sign" ``` -------------------------------- ### Initialize Godot Engine Instance Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/api-reference/RTNGodot.md Creates and initializes a Godot Engine instance with command-line arguments. Must be called within a worklet context. Android and iOS have different path configurations. ```typescript import { RTNGodot, runOnGodotThread } from "@borndotcom/react-native-godot"; import * as FileSystem from "expo-file-system/legacy"; import { Platform } from "react-native"; function initGodot() { runOnGodotThread(() => { "worklet"; if (Platform.OS === "android") { RTNGodot.createInstance([ "--verbose", "--path", "/main", "--rendering-driver", "opengl3", "--rendering-method", "gl_compatibility", "--display-driver", "embedded" ]); } else { RTNGodot.createInstance([ "--verbose", "--main-pack", FileSystem.bundleDirectory + "main.pck", "--rendering-driver", "opengl3", "--rendering-method", "gl_compatibility", "--display-driver", "embedded" ]); } }); } ``` -------------------------------- ### Pass JavaScript Function to Godot for Callable Execution Source: https://github.com/borndotcom/react-native-godot/blob/master/README.md Shows how to pass a JavaScript function to a Godot method that expects a Callable. The GDScript example defines the method on the Godot side. ```gdscript extends Node class_name RNInterface func test_callable(c: Callable) -> void: c.call("Hello from Godot") ``` ```typescript const Godot = RTNGodot.API(); const engine = Godot.Engine; const sceneTree = engine.get_main_loop(); const root = sceneTree.get_root(); const iface = root.find_child("RNInterface", true, false); iface.test_callable(function(s: string) { console.log("Received text from Godot: " + s) }); ``` -------------------------------- ### Production Build Commands for Android Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/configuration.md Commands to perform a production build for Android, including Gradle build. ```bash # Android cd example/android ./gradlew assembleRelease ``` -------------------------------- ### iOS Native Bridge Data Flow Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/module-architecture.md This diagram outlines the data flow for the iOS native bridge, showing how an ObjC module request is processed by NativeGodotModuleProvider to install JSI functions. ```text ObjC Module Request ↓ NativeGodotModuleProvider ↓ Creates or returns RTNGodotModule ↓ JSI Functions installed ↓ Returns module to React Native ``` -------------------------------- ### Initialize Godot for iOS Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/configuration.md Initializes the Godot instance on the Godot thread with specific arguments for iOS, including rendering drivers and methods based on whether the device is a physical device or a simulator. ```typescript import { RTNGodot, runOnGodotThread } from "@borndotcom/react-native-godot"; import * as FileSystem from "expo-file-system/legacy"; import * as Device from "expo-device"; function initGodotIOS() { runOnGodotThread(() => { "worklet"; const args = [ "--verbose", "--main-pack", FileSystem.bundleDirectory + "main.pck", "--display-driver", "embedded", ]; if (Device.isDevice) { args.push( "--rendering-driver", "metal", "--rendering-method", "mobile" ); } else { // Simulator often performs better with compatibility mode args.push( "--rendering-driver", "opengl3", "--rendering-method", "gl_compatibility" ); } RTNGodot.createInstance(args); }); } ``` -------------------------------- ### Build LibGodot from Source Source: https://github.com/borndotcom/react-native-godot/blob/master/README.md Build LibGodot from source for release or development libraries. You can comment out unnecessary lines in the build script if building for a single platform. ```sh cd libgodot ./build_prebuilt_release.sh # for release libraries # OR ./build_prebuilt_dev.sh # for development libraries ``` -------------------------------- ### Configure Gradle for ABI Mismatch on Android Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/errors.md Use `packagingOptions` in `android/app/build.gradle` to resolve ABI mismatch errors by picking the correct shared library. ```gradle // In android/app/build.gradle android { packagingOptions { pickFirst 'lib/arm64-v8a/libc++_shared.so' pickFirst 'lib/x86_64/libc++_shared.so' } } ``` -------------------------------- ### Instantiate Godot Vector2 Object Source: https://github.com/borndotcom/react-native-godot/blob/master/README.md Demonstrates how to create a new Godot Vector2 object using its constructor. ```typescript var vector = Godot.Vector2(); ``` -------------------------------- ### Initialize Godot Cross-Platform Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/configuration.md Initializes the Godot instance on the Godot thread with arguments that adapt to the target platform (Android or iOS). It selects rendering drivers and methods suitable for each platform. ```typescript import { RTNGodot, runOnGodotThread } from "@borndotcom/react-native-godot"; import { Platform } from "react-native"; import * as FileSystem from "expo-file-system/legacy"; function initGodot() { runOnGodotThread(() => { "worklet"; const args = [ "--verbose", "--display-driver", "embedded", ]; if (Platform.OS === "android") { args.push( "--path", "/main", "--rendering-driver", "opengl3", "--rendering-method", "gl_compatibility" ); } else { args.push( "--main-pack", FileSystem.bundleDirectory + "main.pck", "--rendering-driver", "metal", "--rendering-method", "mobile" ); } RTNGodot.createInstance(args); }); } ``` -------------------------------- ### File Organization Structure Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/README.md Illustrates the typical directory structure for a project using the react-native-godot library, showing the placement of API references, type definitions, and configuration files. ```text /output/ ├── README.md # This file ├── api-reference/ │ ├── RTNGodot.md # Main module API │ └── RTNGodotView.md # Component API ├── types.md # Type definitions ├── configuration.md # Setup and configuration ├── errors.md # Error catalog and debugging └── module-architecture.md # Internal architecture ``` -------------------------------- ### Initialize Godot Engine on Godot Thread Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/README.md Use `runOnGodotThread` to execute `RTNGodot.createInstance` on the dedicated Godot thread. The 'worklet' directive is mandatory for functions intended to run on this thread. ```typescript import { RTNGodot, runOnGodotThread } from "@borndotcom/react-native-godot"; // Run on Godot thread await runOnGodotThread(() => { "worklet"; // Required magic string RTNGodot.createInstance([...]); }); ``` -------------------------------- ### Initialize Godot Engine Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/api-reference/RTNGodot.md Initializes the Godot Engine instance with specified arguments and verifies its creation. This function should be run on the Godot thread. ```typescript function initGodot() { runOnGodotThread(() => { "worklet"; RTNGodot.createInstance([ "--verbose", "--path", "/main", "--rendering-driver", "opengl3", "--rendering-method", "gl_compatibility", "--display-driver", "embedded" ]); const Godot = RTNGodot.API(); console.log("Godot initialized:", RTNGodot.getInstance() !== null); }); } ``` -------------------------------- ### TypeScript Build Configuration Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/configuration.md Specifies TypeScript compilation settings for building the project, including included files. ```json { "extends": "./tsconfig.json", "include": ["js/**/*.ts", "js/**/*.tsx"] } ``` -------------------------------- ### Add TypeScript Logging for Godot Initialization Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/errors.md Implements detailed logging within TypeScript to track the initialization process of Godot on the Godot thread. This helps in diagnosing issues during instance creation and API access. ```typescript import { RTNGodot, runOnGodotThread } from "@borndotcom/react-native-godot"; async function debugGodot() { console.log("[DEBUG] Starting Godot init"); try { await runOnGodotThread(() => { "worklet"; console.log("[GODOT_THREAD] Godot thread started"); RTNGodot.createInstance(["--verbose", "--display-driver", "embedded"]); console.log("[GODOT_THREAD] Instance created"); const Godot = RTNGodot.API(); console.log("[GODOT_THREAD] API accessed"); const engine = Godot.Engine; console.log("[GODOT_THREAD] Engine obtained"); }); console.log("[DEBUG] Godot init succeeded"); } catch (error) { console.error("[DEBUG] Godot init failed:", error); } } ``` -------------------------------- ### Open and Close a Godot Subwindow Source: https://github.com/borndotcom/react-native-godot/blob/master/_autodocs/api-reference/RTNGodotView.md Demonstrates how to open and close a specific Godot subwindow using `runOnGodotThread`. Ensure the 'AppController' node exists in your Godot scene to handle window management. ```tsx import React, { useEffect } from "react"; import { View, StyleSheet, Button } from "react-native"; import { RTNGodotView, RTNGodot, runOnGodotThread } from "@borndotcom/react-native-godot"; import { NavigationContainer, useNavigation } from "@react-navigation/native"; export function SubwindowScreen() { const navigation = useNavigation(); useEffect(() => { openSubwindow(); return () => { closeSubwindow(); }; }, []); function openSubwindow() { runOnGodotThread(() => { "worklet"; const Godot = RTNGodot.API(); const engine = Godot.Engine; const sceneTree = engine.get_main_loop(); const root = sceneTree.get_root(); // Call a method on the Godot app's controller to open the subwindow const controller = root.find_child("AppController", true, false); if (controller) { controller.open_window("subwindow"); } }); } function closeSubwindow() { runOnGodotThread(() => { "worklet"; const Godot = RTNGodot.API(); const engine = Godot.Engine; const sceneTree = engine.get_main_loop(); const root = sceneTree.get_root(); const controller = root.find_child("AppController", true, false); if (controller) { controller.close_window("subwindow"); } }); } return (