Last active
January 20, 2025 06:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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