Jump to content

Some questions on importing models from blender into Unity


Recommended Posts

I finished making the model/texture for my photon-sail and am unsure what to do next. I know that I have to import them into Unity, but this raised some questions:

1) The model is made of multiple blender objects, do I have to join them into a single object before importing?

2) If I need to join them together, how will that affect the animation I created (animations have been created for each of the blender objects separately, that happen simultaneously)?

3) How do I add a thrust-vector transform to the part to make it an engine?

4) I also need to have ModuleDeployablePart on the part, how do I assign the animation I have created to this module.

Thanks in advance.

Link to comment
Share on other sites

Welcome to the wonderful and frustrating world of modding! As far as your questions:

1) No you don't need to join them - they can be collected in the .cfg file but I like to create an empty that all the pieces are parented to. When I export from Blender I select that root empty and in the export options I export selected and children.

2) If you parent to an empty you'll only have one model in Unity and one animation. Note that Unity will Add a Animator. You need to remove this and add a Animation. And don't forget to set the animation to Legacy.

3) The thrust vector is a empty you add to you model (I add mine in Blender - You may be able to add in Unity) with the Z (blue) axis pointing in the direction of thrust - in other words out the nozzel. Then in the cfg set the thrustTransform (or whatever it's named) to the name of the empty. A note here - Unity will change the names sometimes - for example A.B in Blender becomes A_B in Unity - you need to use the Unity name.

4) In you .cfg file you add the ModuleDeployablePart and set the "animationName" to the name of your animation - whatever you set it to in Unity.

Happy modding!

Edited by wasml
Link to comment
Share on other sites

Where would I find this? I'm new to the Unity Editor UI. The animations don't show up in the inspector or hierarchy tabs. Figured this out.

EDIT: I compiled the part model and tried loading it into the game, but it doesn't show up at all. It's also very difficult to narrow down the problem, the log file doesn't say anything about why the model wasn't loaded. I was using this guide:

But it seems to be very outdated, could anyone tell me what I have to do different from this guide?

This is rather frustrating, why hasn't anyone updated this guide?

Also, I saw some errors when importing PartTools, such as nullref errors. I also can't seem to use the KSP shaders, they come up with further errors.

Spoiler

KSP shaders error:

"failed to open source file: '../CustomUnityShadowLibrary.cginc'
Compiling Vertex program with UNITY_PASS_FORWARDBASE DIRECTIONAL
Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_FULL_HDR")

Null reference exceptions:

The nullref exception: "NullReferenceException: Object reference not set to an instance of an object
UnityEditor.InspectorWindow.ShouldCullEditor (UnityEditor.Editor[] editors, System.Int32 editorIndex) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1658)
UnityEditor.InspectorWindow.DrawEditors (UnityEditor.Editor[] editors) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1488)
UnityEditor.InspectorWindow.RebuildContentsContainers () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:724)
UnityEditor.InspectorWindow.RedrawFromNative () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:324)"

All the KSP shaders (like Diffuse, specular) are all under the failed to compile dropdown, looks like I've made an error in the installation of part tools, but I followed the instructions exactly, so I don't know what's going on.

Edited by Aniruddh
Compiled part, didn't work
Link to comment
Share on other sites

I had trouble with the 1.10 parttools too (see this thread)- dropped back to the 1.9 tools. For making parts 1.9 works fine - missing new new 1.10 shaders but I'm not sure if any of these are even for parts. There are a number of things that can cause the part not to show up - hard to say without seeing your config and log file (not that I would necessarily be able to tell even then). Not sure it will help any but I put together a batch of Blender/Unity projects for the parts I've been able to figure out - includes some notes with problems I've run into and figured out.

A quick review of that tutorial link - nothing jumped out as out of date - part mods haven't changed much since early on (wheels being the exception)

Link to comment
Share on other sites

My part is finally working! It shows up in game correctly. However, there are a few errors, the collision mesh I am using was created in blender, and is in the wrong orientation, how would I rotate the collision mesh from within Unity? Also, my part looks quite bad, which KSP shader do I add to make it shiny and reflect it's surroundings (like the stayputnik probe texture in recent versions). I'm not talking about the KSP specular shader, that just reflects light of a particular color that is pre-determined, not changing based on surrounding light

Edited by Aniruddh
Link to comment
Share on other sites

 

On 9/11/2020 at 11:08 AM, Aniruddh said:

My part is finally working!

Quite a thrill no? :D

In the upper left corner of the Unity screen, just under "File", is a hand icon. The buttons to the right of the hand are the various manipulation tools - mouse over for a tool tip. I don't know which shader the Stayputnik uses but would try the LightWrapped/Specular.

Link to comment
Share on other sites

32 minutes ago, wasml said:

Quite a thrill no? :D

Yes it is!

32 minutes ago, wasml said:

I don't know which shader the Stayputnik uses but would try the LightWrapped/Specular.

I tried that, and unfortunately it just makes the part really bright. I know this is a stock feature, and that should hopefully mean I don't have to write code or use another plugin to make a shader reflective. I also see many modders use it, like in the solar panels in Near Future.

Link to comment
Share on other sites

I've used specular and in the VAB it seems to reflect the windows and door (in a blurry way) but when I get the part out on the pad it's a lot duller. I thought I saw a setting in the setup menu to improve this but haven't gone back to look for it again.

Link to comment
Share on other sites

6 minutes ago, wasml said:

I've used specular and in the VAB it seems to reflect the windows and door (in a blurry way)

How? For me it only reflects white light in a sort-of diffuse way.  What settings (on the inspector tab) are you using for the material? 

Thanks!

Link to comment
Share on other sites

The specular shader uses alpha for shinniness - What alpha is used for depends on the shader. If you click on a material that's set to KSP/Specular and look at the inspector - near the top - you'll see "_MainTex (RGB spec(A))". The spec(A) tells you the Alpha channel is specular. I haven't checked but I think many of the KSP shaders use alpha for shine. If you pick KSP/Alpha/Translucent Specular you'll notice it has "MainTex(RGBA)" - I haven't used this but am guessing in this case alpha is translucent (The model I have loaded seems to agree).

As I mentioned above - the specular shader looks nice and shiny in the VAB but on the pad it's much duller - I do have the graphics setting turned down - may or may not be the reason.

Edit: ShadowMage has an add-on that judging from the screen shots has some spectacular results - I'll post a link here if when I find it.

Edited by wasml
Link to comment
Share on other sites

16 hours ago, wasml said:

ShadowMage has an add-on that judging from the screen shots has some spectacular results - I'll post a link here if when I find it.

I believe you are referring to Textures Unlimited. It does makes this much easier, on the other hand I'm making these models for a mod that is meant to be completely standalone.

16 hours ago, wasml said:

_MainTex (RGB spec(A))

I was wondering if that had anything to do with it, thanks for clarifying!

Edit: No matter what I do to the alpha channel, it always makes the part translucent in the game, rather than reflective. I used the specular shader, which means the texture's alpha channel should be used for specularity.

Edited by Aniruddh
Link to comment
Share on other sites

I think it was the Specular Bumped(Mapped) that I started with but found parts were invisible if I dropped them in the editor without attaching them. They weren't transparent once attached though. I'm now using the plain Specular and they do give shine without transparency. Would suggest you try the plain specular if you aren't already - if that gives you transparency instead of shine I'm at a loss as to why.

Link to comment
Share on other sites

This is unusual, it seems it has got nothing to do with the texture, I switched the material to using a different (definitely completely opaque) texture, and the object in the model still appeared transparent. So it has something to do with the material itself. I created a new material and the transparency is gone, but still no clear reflection.

Edit: Turns out adding an alpha channel does nothing. So does using a layer mask to edit the alpha channel. @wasml could you go through the exact steps (from to start to finish) to get your texture to be reflective, or maybe link to a tutorial on the forums? Thanks. Also, for the part demo you've linked, could you point me to which part s(if any) have flags?

Edited by Aniruddh
Link to comment
Share on other sites

One thing occurred to me - if your faces in blender are backwards they don't show in KSP - turn on Backface culling in blender and you can see this. In Blender 2.73 the pullout on the right side by the outliner (assuming you haven't rearranged things from the default) - has the transforms, rotations, 3D view location etc. - a little ways down is a "Shading" group - in this is the backface culling checkbox. Though your third sentence (new material solves the problem) suggests backface culling isn't your problem.

As far as parts with flags - do you mean tags? If so the airlock, ladder and engine use tags.

And an attempt to list the steps for a reflective material (Note: very reflective in the VAB - not so much on the pad - YMMV).
1) In Gimp create your texture then right click on it and in the drop down select "Add Layer Mask"
2) Select the layer mask and fill with a color from black (Non-reflective) to white(Max reflective).
3) "Export As" and create a png (use dds and select DD5 for final texture (DD5nm for final normal maps))
4) In Unity create a new Material and at the top in the inspector select "KSP\Specular" - then add the png as the texture
5) Select one or more of your meshes in the Hierarchy and drag and drop this material into the blank area below the mesh renderer - the model should now be wearing your texture. Note that it may be transparent - don't worry - looks different in KSP.
6) Write the .mu file and test in KSP

If this is hard to follow I can try to make some screen shots but may be this weekend before I can get around to it. Don't get too discouraged - this gets easier after you've done it a few times and found the pitfalls.

Link to comment
Share on other sites

13 hours ago, wasml said:

1) In Gimp create your texture then right click on it and in the drop down select "Add Layer Mask"

This is the section I'm confused on. For me when I click on that, a list of options comes up, such as 'White (Full Opacity)' or 'Layer's alpha channel', which option should I use for this? I normally just use 'Black (full transparency)' when using GIMP to create transparent backgrounds.

14 hours ago, wasml said:

If this is hard to follow I can try to make some screen shots but may be this weekend before I can get around to it.

No need, screenshots take a long time to collate, and they won't likely be that helpful here.

Link to comment
Share on other sites

10 hours ago, Aniruddh said:

which option should I use for this?

Which option doesn't really matter. Personally I often use the gray scale option as it leaves the different sections as different colors - makes it easier to see where the non-alpha details are. I usually end up replacing everything anyway if with nothing more than a flood fill.

Edit/Disclaimer: I'm striving for "passable" textures my self - would judge texturing to be my weakest skill so take this advise with a grain or two of salt.

Edited by wasml
Link to comment
Share on other sites

Ok, I was randomly messing around with shaders, and I forgot to set the shader back to one under KSP, and it turns out now reflections work!  :D 

I used the Standard (specular setup) shader in Unity. I'm surprised the game didn't crash. I'm going to test this further to see if there are any problems with this, if not I'll stick to it. I tried all that in GIMP and nothing seems to work, so this feels like a better option for now.

Also, I'm using an emissive map for the engine nozzle. The emissive map works, as well as the emissive animation. Only problem is the emissive map shows up on the model all the time,. It makes the areas that should glow when the engine is off, be a slightly lighter color of grey all the time (it treats an emissive map as an actual texture) , how do I make it disappear when the engine isn't on? It is subtle, so it isn't a huge problem, but it does look unnatural (glow in the dark) in certain lighting

Edited by Aniruddh
Link to comment
Share on other sites

I've only made a few engines and haven't run across anything like that and nothing comes to mind - afraid I can't help. If you do solve it I'd be interested in how - I'll add to my list of solutions.

Looking at the emissive I did get to work - has the following cfg:

	MODULE
	{
		name = FXModuleAnimateThrottle
		animationName = GimbalEngineEmissive	// Unity color animation name
		responseSpeed = 0.001
		dependOnEngineState = True
		dependOnThrottle = True
	}

I would think the problem would be in that module - good luck!

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