MechJeb2

MechJeb2

4M Downloads

[DEV] - Does a stable part "identifier" exists?

SPD13 opened this issue ยท 2 comments

commented

Hi,
I am facing an dev problem in the script module. I need to find a way to identify a unique Part among the Vessel(s) that is consistent across all the Vessel's instanciations (Load, Scene change, etc...)
For example, in the script modules where i need to select a Docking port, i create a list of the existing docking ports before the lift-off and in the script module configuration, i store the index of this part in the list. Next time the script is loaded, i iterate again on the vessel to find the docking ports and select the same index in the list. But if the vessel structure has changed, the Part i will be referring is not the correct one and may even not exist any more on the vessel.
Is there somewhere a unique identifier for a part that stays consistent?
I tried "GetInstanceID" but it's changing when the game is loaded
I tried to force an ID on the "part.tag" but i can't set it.
Thank you for the help

commented

Part.flightID should be stable but only outside the editor.

commented

Thanks ! it should make it. I believed flightID is the same for all parts but it seems different for each part and represents the instance of a part for a specific flight. I will rely on the index prior to the launch and then partID after the launch.
Thanks again for your help.