Jump to content

Creating new attach nodes at runtime using AddAttachNode?


Recommended Posts

Has anyone worked with the AddAttachNodes method before?

I'm looking to add new attach nodes to existing parts at runtime (no cfgs involved). It seems adding the node directly to part.attachNodes causes crashes, so I think the AddAttachNode method might be the way to go.

It takes a ConfigNode parameter, which could be pretty much anything. I tinkered around with it for more information, and here's what I could discern:

- The name of the overall ConfigNode doesn't look like it matters.

- The parameter must contain the value 'name', which will be the final attach node name

- The parameter must contain the value 'transform', which is the name of a Unity Transform object (but not just any old transform.name).

The big hangup here is the third point -- I can't figure out what 'transform' should be.

If anyone can explain this method, or the 'transform' bit, it would be a huge help.

Thanks!

Link to comment
Share on other sites

I guess transform could be a dummy transform you created like so


Transform DummyTransform = new Gameobject () as transform;

dont have access to a computer now so not sure if

thats correct. Otherwise you could do:


Gameobject dummy = new Gameobject ();
Transform dummyTransform = dummy.transform;

Its position (transform.position) is probably used to place the attachnode when invoked this way. So its probably a good idea to set its position first

But im a noob with c#. Im also doing some wierd stuff with attachnodes and really wish there was some good resources on how to work with them in code

Edited by landeTLS
Link to comment
Share on other sites

transform is the name of a transform of the model. One in the model hierarchy. You could add one manually but you would have to use the part transform as a partent.

Link to comment
Share on other sites

The method won't take a dummy transform. I can't pass it "new GameObject('blah').transform.name": it will say "Cannot add attach node. Transform of name 'blah'".

transform is the name of a transform of the model. One in the model hierarchy. You could add one manually but you would have to use the part transform as a partent.

I'm not too familiar with Unity. Is this the model hierarchy from the Unity framework, or is it something KSP added? I thought creating a new GameObject would automatically add it to the Unity hierarchy.

Anyways, here's my code for adding the node in OnStart:

        if (state == StartState.Editor)
{
Transform t = new GameObject("interstageNode").transform;
ConfigNode cn = new ConfigNode("interstageConfig");
cn.AddValue("name", "node_stack_interstage");
cn.AddValue("transform", t.name);
part.AddAttachNode(cn);
}

Actually, I just had a thought. Could it be that I'm trying to add the node as I'm bringing it up in the editor? I'll try adding the node outside of the editor when I get back to my computer tonight.

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...