Skip to reading
GDScript Programming & Godot

54. Build a clean native extension

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page

A reliable extension has four pieces: a clear entry point, owned native nodes, a public adventure interface, and cleanup. The native button and cube examples show the pattern without changing the engine’s source.

Source table from 54. Build a clean native extension, page 64
PartExample decision
EntryA GUI button calls run, or a subscribed room event starts the feature.
StateSaved puzzle state stays in Variable; transient node references stay in a global script.
OwnershipNative UI is a script child; room visuals are attached to the room and cleaned up on replacement.
CommunicationUse PCA actions/events for adventure work and signals for local nodes.
CleanupStop timers, remove temporary nodes, and tolerate room changes invalidating references.
DistributionInclude actual resource files and test the exported game, not only the editor.

Keep the GDScript record small enough to understand. When the project needs a larger file-backed component, put that component in a custom folder in the editable Godot project and leave a small PCA bridge around it.

A native extension is most useful when it adds something concrete: a special inspection view, a custom control, an external data reader or a visual effect that the authored actions do not already cover.

Page 64 of 378Permalink
Go to page