Jump to content

[Solution]gameobject.transform.parent breaks scenariomodule


Cyrik

Recommended Posts

Hey,

I just wanted to post this so the next guy running into it wont spend forever trying to figure it out.

Here's the offending plugin:

    [KSPScenario(ScenarioCreationOptions.AddToAllGames,GameScenes.FLIGHT)]    
public class Class1 : ScenarioModule
{
private Transform _origTransform;
public void Start()
{
Debug.Log("[MRO] init");
_origTransform = gameObject.transform.parent;
gameObject.transform.parent = null;
}

public void OnDestroy()
{
Debug.Log("[MRO] destroy");
}
}

This plugin will load once on the flight scene, then it will get destroyed when you switch crafts and wont be reinitialized. Actually when you set gameobject.transform.parent to nearly anything it gets broken. The only way around it i found is to set it back to gameObject.transform.parent = _origTransform; in OnDestroy or somewhere else.

Edited by Cyrik
changed constructor to Start call
Link to comment
Share on other sites

I'm not sure you should be using a constructor for a scenario module. KSP will create a list of all the protoscenariomodules in Game. If you need an instance of your scenario module you can just pull it out of that.

Edit: Actually you shouldn't use constructors with any monobehaviour: http://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html. They should only started with KSP attributes or by manually adding with gameObject.AddComponent.

Edited by DMagic
Link to comment
Share on other sites

I'm not sure you should be using a constructor for a scenario module. KSP will create a list of all the protoscenariomodules in Game. If you need an instance of your scenario module you can just pull it out of that.

Edit: Actually you shouldn't use constructors with any monobehaviour: http://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html. They should only started with KSP attributes or by manually adding with gameObject.AddComponent.

Thank you, I´ll fix that part. Sadly the problem still stands. Even if you change the gameobject.transform.parent anywhere else it breaks the whole thing. I just wanted to illustrate it in as little code as possible.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...