Jump to content

using prefabs


codepoet

Recommended Posts

KSP has a class AssetBase that provides a public method GetPrefab(). I assume I can use this to access prefabs for gameobjects priovided by the game, such as attachment node icons, CoM Markers, Models of the VAB. The problem is not knowing what the prefabs are called. Does anyone have experience of doing this, or can offer solutions?

Link to comment
Share on other sites

Hm, i never heard about that class before and couldn't get it to work, so it looks like another dead piece of code. KSP has quite a few of them... some kept for mod-compatibility, others like this for no apparent reason.

You should check out GameDatabase. It lists pretty much everything from GameData... at least Texture, Models and Audio files and you can query them via the Get...(string name) methods. The names there are the same you can find in the ingame debug menu or the objects name property. For vessel related prefabs... PartLoader provided nearly all i ever needed.

Link to comment
Share on other sites

Hm, i never heard about that class before and couldn't get it to work, so it looks like another dead piece of code. KSP has quite a few of them... some kept for mod-compatibility, others like this for no apparent reason.

You should check out GameDatabase. It lists pretty much everything from GameData... at least Texture, Models and Audio files and you can query them via the Get...(string name) methods. The names there are the same you can find in the ingame debug menu or the objects name property. For vessel related prefabs... PartLoader provided nearly all i ever needed.

I do not think it is dead - it is called by the EditorLogic to retrieve the prefab for an Attachment Node Icon when it creates those (which is something I want to do as I am messing around with AttachmentNodes). However the problem is it is not clear what the name of any of the PreFabs are for be able to access them AssetBase::GetPrefab("myPrefab") ought to work, if you know what prefab you want. I tried a brute force attack to try to find something, anything in there, but it quickly became inefficent at more than 6 characters.

Is there a way of asking a GameObject which prefab it came from? Does anyone know what is in the .assets files in KSP_Data, or what format they are in?

Link to comment
Share on other sites

@ codepoet: just a guess here, I don't really know about Prefabs. But if you resorted to a brute force attack to find something...could Prefabs have anything to do with Subassemblies (what goes saved within VAB/SPH)? If you have none in your development copy of KSP, then you would never find one.

Link to comment
Share on other sites

A Prefab is a unity concept - it can be used as a template to create a new GameObject. I know that some are there as the stock game is calling this code to get them, and use them. I just do not know what they are called!

Link to comment
Share on other sites

OK, thanks. Have never gone in depth with Unity objects, and I missed you were not talking about one from KSP itself. Hope I am not actually making you lose time.

But if that is a Unity concept, and KSP uses it as a template to build one of its own objects, then it is very possible that KSP never creates instances of a Prefab, just creates derivative objects based on that. Of course the GetPrefab() method is inherited as well, but I miss to see how you could find anything belonging to the Prefab class, while there may be plenty of objects of other inherited classes.

Link to comment
Share on other sites

I do not think it is dead - it is called by the EditorLogic to retrieve the prefab for an Attachment Node [...]

Okay, i thought the prefab is EditorLogic.attachNodePrefab and directly assigned via Unity. Anyway, have you tried the GameObject's name property? Ksp usually uses them to retrieve prefabs, and if you are lucky it might was not or just slightly changed. Also AssertBase instances do expose lists of all their asserts. Getting that reference should be easy via Object.FindObjectsOfType. That way you can at least look for their names...

Link to comment
Share on other sites

Okay, i thought the prefab is EditorLogic.attachNodePrefab and directly assigned via Unity. Anyway, have you tried the GameObject's name property? Ksp usually uses them to retrieve prefabs, and if you are lucky it might was not or just slightly changed. Also AssertBase instances do expose lists of all their asserts. Getting that reference should be easy via Object.FindObjectsOfType. That way you can at least look for their names...

Of course - get the AssetBase using Object.FindObjectsOfType! Sorry, I was being dull, and could not see the wood for the trees.

Having said that, your are right about EditorLogic.attachNodePrefab - it is being used, but not asigned in the KSP code, which makes me wonder where is comes from (somehow I had concluded it was assetbase, but now I am not so sure!) Could you please explain what you mean by "directly assigned via unity"? How does that work, and in practical terms do I have access to it? I guess I can just use the prefab straigh out of EditorLogic?

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