Skip to content

Instantly share code, notes, and snippets.

@Shilo
Last active January 20, 2025 06:39
Show Gist options
  • Save Shilo/cdc948254c4c89a392d5ec75b4dff2a4 to your computer and use it in GitHub Desktop.
Save Shilo/cdc948254c4c89a392d5ec75b4dff2a4 to your computer and use it in GitHub Desktop.
Godot 4 PackedScene extension to get export property value based on property name.
public static partial class PackedSceneExtension
{
public static Variant? GetNodePropertyValue(this PackedScene packedScene, int nodeIndex, StringName propertyName)
{
SceneState sceneState = packedScene.GetState();
int propertyCount = sceneState.GetNodePropertyCount(nodeIndex);
for (int propertyIndex = 0; propertyIndex < propertyCount; propertyIndex++)
{
if (sceneState.GetNodePropertyName(nodeIndex, propertyIndex) == propertyName)
return sceneState.GetNodePropertyValue(nodeIndex, propertyIndex);
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment