Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interaction system can be cloned and destroyed as part of drag cube generation via b9partswitch #298

Open
JonnyOThan opened this issue Jun 1, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@JonnyOThan
Copy link
Collaborator

JonnyOThan commented Jun 1, 2023

79498 [LOG 14:06:34.615] Can't add component 'LineRenderer' to KVR_HandL because such a component is already added to the game object!
79499 [EXC 14:06:34.617] NullReferenceException: Object reference not set to an instance of an object
79500     KerbalVR.VRUIHand.SetupLineRenderer (UnityEngine.LineRenderer lineRenderer) (at <8f95809a55a44bcea305d855e7cd782c>:0)
79501     KerbalVR.VRUIHand.Awake () (at <8f95809a55a44bcea305d855e7cd782c>:0)
79502     UnityEngine.DebugLogHandler:LogException(Exception, Object)
79503     ModuleManager.UnityLogHandle.InterceptLogHandler:LogException(Exception, Object)
79504     UnityEngine.Object:Instantiate(Part, Vector3, Quaternion)
79505     <RenderDragCubesCoroutine>d__31:MoveNext()
79506     UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
79507     <SetupDragCubeCoroutine>d__47:MoveNext()
79508     UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
79509     B9PartSwitch.ModuleB9PartSwitch:RecalculateDragCubes()
79510     B9PartSwitch.ModuleB9PartSwitch:UpdateOnStartFinished()
79511     B9PartSwitch.ModuleB9PartSwitch:OnStartFinished(StartState)
79512     Part:ModulesOnStartFinished()
79513     <Start>d__323:MoveNext()
79514     UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

The part is cloned in DragCubeSystem.RenderProceduralDragCube, and presumably the camera is a child of this part somewhere.

Further, this probably means that the hands are affecting drag cubes when they're generated like this.

Possible solutions:

  • Move initialization code to Start instead of Awake (Start won't be called on these cloned copies)
  • Detach/reattach flight camera using prefix/postfix patches (might miss other cases where a part can be cloned, if there are any)
  • Have InteractionSystem objects destroy themselves in Awake if they detect that they are not the singleton instance (FlightCamera does this)

KSPCF might also change this behavior:

For what it's worth, the KSPCF drag cube rendering reimplementation will most of the time render the drag cube directly on the part instance, avoiding the cloning altogether.

Note there is an object tag to avoid including renderers in the drag cube: Drag_Hidden

@JonnyOThan JonnyOThan added the bug Something isn't working label Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant