DMagic

KSPedia Creation Tutorial

Recommended Posts

4 minutes ago, DMagic said:

@micha Creating sprites at runtime is definitely expensive, but if done in Unity it's already taken care of by the time it's displayed in KSP.

I've done some more testing and while the filesize is definitely smaller with textures, the display of the images is less sharp than if you import the image as either "Editor GUI and Legacy GUI" or as "Sprite". Adding them as "Image" or "Raw Image" doesn't seem to make a difference here (although obviously if you use "Image" then you have to import as "Sprite").

But nothing I do seems to make the images properly sharp like in your KSPedia entries.
 

4 minutes ago, DMagic said:

For lines like these:

<snip>

I just do them in Photoshop with the the line tool. You can hold ctrl, or alt, or something to make them snap to 45o increments. They don't always come out perfect, if you look closely you can see the gaps between some of the segments, and it's also a pain because any time you need to move the text you have to move the lines around, too, but it works well enough for me.

Yes exactly :)

Hmm, ok, but how do you line them up with the text? I've had a look at your GitHub repo for the images and yeah, you just have the lines as part of your images, but that must have been a royal PITA to line up...?  I guess it is what it is..!

Share this post


Link to post
Share on other sites
On 06/09/2017 at 7:06 PM, DMagic said:

Keep in mind that this does not update any actual text changes in the final KSPedia entry. I think this is mentioned briefly in the tutorial.The Part Tools reads the actual text from an XML file in your Unity project folder (I'm not sure about the exact name or location of the file). The only way to update the XML file without going through the whole process with setting up the KSPedia pages is to manually update the text in the XML file.

<...>

It's possible that this is fixed in the 5.4 Part Tools.

I haven't worked out when it works and when it doesn't, but sometimes text changes are applied and other times not. It's very frustrating. And no, it's not fixed in the latest PartTools.

EDIT: Ok, so it looks like the following happens:

When you first create an entry in the KSPedia using the KSPedia tool, it sets up the information in the XML file, and copies any text into the XML.  But if you change text in an existing item, it does not get updated!

However; if you delete all the <text>...</text> tags out of the XML, it will now take the text directly from the prefab when re-generating the AssetBundle. Of course, this only applies for existing items; any new items have the same issue as above.

TL;DR: After adding any new entries using the KSPedia tool, open the kspedia XML file and delete all <text> tags out of it to ensure the text is taken directly from the prefabs.

 

On 18/11/2017 at 5:49 PM, micha said:

<...>
But nothing I do seems to make the images properly sharp like in your KSPedia entries.
<...>

Looks like my main issue has been not capturing sharp-enough images from the game itself. They looked fine in-game, but were horrible in the KSPedia.  I've since been paying more attention to the quality, and there's a particular zoom-level in-game where the textures suddenly "snap" into focus. My new captures have been at that zoom-level and they look much better in KSPedia.

So to re-cap, in my experimenting I've found that for the smallest KSPedia filesize and best image quality, you will want to import your images as "Editor GUI and Legacy UI", then add them to your prefab as "Raw Image". This can more than halve the final size compared to importing the images as Sprites, regardless of whether you then use the Sprite texture as a "Raw Image" or an "Image" in your prefab.  I've also got up to half-a-dozen or more separate images on a page instead of using DMagic's method of combining them all onto one big image. The benefit, apart from being able to freely re-arrange them in Unity, is that you can re-use them on other pages without them taking up more resources.

There may be benefits to doing it DMagic's way though; I haven't actually profiled the game while it's running.

Edited by micha

Share this post


Link to post
Share on other sites

I recently discovered a simple way to modify KSPedia entries to add custom effects. Since these are all standard Unity components you can simply add any script to a KSPedia component and have it do whatever you want. It requires coding, but not necessarily anything complicated.

The example I have is of making a kind of simple GIF (I don't think actual GIFs are supported by Unity's image formats).

I make a KSPedia page in the standard way, add an image, then add a custom script to it that cycles through multiple images in a given time frame.

This is the total code required for this effect:


using System.Collections;
using UnityEngine;
using UnityEngine.UI;

namespace UniversalStorage.Unity
{
    [RequireComponent(typeof(Image))]
    public class KSPediaImageCycler : MonoBehaviour
    {
        [SerializeField]
        private Sprite[] m_Images = null;
        [SerializeField]
        private float m_Delay = 3;

        private Image _image;
        private Coroutine _cycler;
        private int _counter;

        private void Awake()
        {
            _image = GetComponent<Image>();
        }

        private void OnEnable()
        {
            if (_cycler != null)
                StopCoroutine(_cycler);

            _cycler = StartCoroutine(CycleImages());
        }

        private void OnDisable()
        {
            if (_cycler != null)
                StopCoroutine(_cycler);

            _cycler = null;
        }

        private IEnumerator CycleImages()
        {
            WaitForSeconds wait = new WaitForSeconds(m_Delay);

            while (gameObject.activeInHierarchy)
            {
                yield return wait;

                _counter++;

                if (_counter >= m_Images.Length)
                    _counter = 0;

                _image.sprite = m_Images[_counter];
            }

            _cycler = null;
        }
    }
}

This script has to be compiled and the plugin added to your Unity Assets/Plugins folder. This means that anything you want to add to KSPedia has to be done in a separate .dll assembly than what you might already be using for KSP, since anything referencing the KSP plugins can't be imported into Unity.

What you do is select the Image component that you want to use in your KSPedia page, then add this script to it, then add all of the files that you want to cycle through to the m_Images array. You can set the time between changes by setting a value for the m_Delay field:

Qj91O5k.png?1

 

Then make sure to add the plugin to your mod folder in KSP's GameData folder (if you don't the KSPedia page will still work, it just wont use any custom scripts you've added and the log file will complain). The result is this:

BM0Qfp2.gif

 

This could be expanded to do basically whatever you want within the limits of Unity. You could add things like buttons to make the page interactive, or even add a working copy of a UI if you really wanted to.

 

On 11/19/2017 at 2:04 PM, micha said:

So to re-cap, in my experimenting I've found that for the smallest KSPedia filesize and best image quality, you will want to import your images as "Editor GUI and Legacy UI", then add them to your prefab as "Raw Image". This can more than halve the final size compared to importing the images as Sprites, regardless of whether you then use the Sprite texture as a "Raw Image" or an "Image" in your prefab.  I've also got up to half-a-dozen or more separate images on a page instead of using DMagic's method of combining them all onto one big image. The benefit, apart from being able to freely re-arrange them in Unity, is that you can re-use them on other pages without them taking up more resources.

I haven't done any testing. But I think this may be due to texture compression, or the lack of compression, and textures with dimensions in powers of 2. When you add a sprite to Unity with a size that does not conform to a power of 2, a full size page of 2048*1536, for instance, it won't get compressed, or at least not to the same degree as a 2048*2048 texture. So maybe the best way is use separate textures for each image element and just make sure they are all powers of 2, probably 512*512 or 256*256 in most cases, and set compression to Normal or Low.

For this single test page I had four sprites of about 400*500 and I was getting a ~800kb .ksp file, when I changed them all to 512*512 the file size was reduced to ~200kb.

Share this post


Link to post
Share on other sites

@Elon Kerman Jr This works fine in 1.4. You probably want to use the version of Unity that matches KSP (2017.1) and the latest version of the part tools for the version of Unity. Otherwise everything works the same as before.

Share this post


Link to post
Share on other sites

Hello. I am having some problems with using the KSPedia Database to make KSPedia entries for my mod.

Screen_Shot_2018-08-22_at_5.05.57_AM.png

Screen_Shot_2018-08-22_at_5.06.02_AM.png

When I open the KSPedia Database, it is completely blank (as contrary to the tutorial's view of it). I am new to Unity, and am not sure what I'm doing wrong. Can you help?

Share this post


Link to post
Share on other sites
6 hours ago, DMagic said:

@SnailsAttack You are using Unity 2018, you must use the version of Unity that matches the Part Tools, 2017.1 for KSP 1.4.

I downgraded my Unity version and it worked fine. Unfortunately, I suspect that making entries for my two dozen kopernicus planets is going to be a rather long process. Oh well. Thanks for your help!

Share this post


Link to post
Share on other sites

Hello guys,

Not sure if I am doing something wrong, but i cannot build anything.
If followed the first steps in the tutorial and when i try to build use the asset compiler i get the following message:

TypeLoadException: Could not load type 'KSPFontAsset' from assembly 'KSPAssetCompiler, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null'.
UnityEditor.Build.BuildPipelineInterfaces.InitializeBuildCallbacks (BuildCallbacks findFlags) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:109)
UnityEditor.BuildPipeline:BuildAssetBundles(String, AssetBundleBuild[], BuildAssetBundleOptions, BuildTarget)
KSPAssets.Editor.AssetCompiler:BuildAssetBundles(Boolean, Boolean, String, String[])
KSPAssets.Editor.<BuildBundle>d__6:MoveNext()
KSPAssets.Editor.EditorUtil:UpdateCoroutine()
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

Am I missing something or does more people get the problem?? I am using Unity 2017.1.3f1 as instructed with the PartTools.
I have tried everything with and without TMP added to the project, they give the same problem.

Also if I try to build the KSPFontAsset manually via Assets > KSP Fonts > Generate KSPFontAsset i get the following error:
FileNotFoundException: Could not load file or assembly 'TextMeshPro-2017.1-1.0.56-Runtime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.

Share this post


Link to post
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.