<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by FredericRP on Medium]]></title>
        <description><![CDATA[Stories by FredericRP on Medium]]></description>
        <link>https://medium.com/@FredericRP?source=rss-68ea6eb92824------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*UkFFj6VSvEscqMIYaOTYvg.jpeg</url>
            <title>Stories by FredericRP on Medium</title>
            <link>https://medium.com/@FredericRP?source=rss-68ea6eb92824------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 23:46:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@FredericRP/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Immerse players with Unity: add live audio waveforms effortlessly!]]></title>
            <link>https://medium.com/@FredericRP/audio-waveform-3127419455c4?source=rss-68ea6eb92824------2</link>
            <guid isPermaLink="false">https://medium.com/p/3127419455c4</guid>
            <category><![CDATA[free]]></category>
            <category><![CDATA[assets]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[audio]]></category>
            <dc:creator><![CDATA[FredericRP]]></dc:creator>
            <pubDate>Fri, 12 Apr 2024 10:01:25 GMT</pubDate>
            <atom:updated>2024-04-12T10:06:26.907Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever thought it would be cool to include the live audio waveform of an NPC inside your game and at the same time postpone because it would be so difficult? In fact, it’s mind blowingly easy to do so in Unity.</p><figure><img alt="A pixelated audio wave form imagined by me, created with AI" src="https://cdn-images-1.medium.com/max/1024/1*YT2YneVwG3Nz_C0Mr678NQ.png" /><figcaption>A pixelated audio wave form (imagined by me, created with AI)</figcaption></figure><h4>The idea</h4><p>When I created a podcast talking about managing a small indie studio and interviewing some french stars of such studios, it was right before Covid-19 happened. What caused the majority of gamers go online most of their time, made me go offgrid as there were such poor network where I lived. Obviously I could not record a podcast with both audio and video at that time, so to widen the audience of it, I thought it would be cool to create a video from the audio part only, then integrate a slideshow and adding a sort of live feature in it by including audio waveform of the interviews.</p><h4>The prototype</h4><p>I’m more an expert of Unity than any video editing software so it was easier for me to study how doing it inside Unity. And I discovered quickly that creating an audio waveform is quite an easy task. Here are the steps I went through:</p><ul><li>use the audio listener to get the list of values per frequency</li><li>manipulate the values from the list to get values usable in the waveform</li><li>create or update a texture from thoses values to display it</li></ul><p>You can get something from it, but it is not what we are used to see when we see audiowaveform since the frequencies increase exponentially and not linearly. By tweaking some of the parameters you can retrieve from the audio listener, I was able to get a pretty good result as you can see below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*wLouLjX_oks8heAcood_Ig.png" /><figcaption>Audio wave form sample</figcaption></figure><p>In the image above, as in the sample project, I have added a mirrored image to make it cooler, but what you get is only the bright upper part of the image, it’s up to you to make it look like what you want.</p><h4>Audio wave configuration</h4><p>Download and import the project, open the sample scene, press Play and you will see the audio wave form as in the title of this post.</p><p>Some parameters are available directly from the audio listener, some others I have added them myself as it was missing to get a pretty result. Here are the explanation for them:</p><ul><li><strong>lerp speed</strong>: it can go pretty fast and you won’t see anything if there is no lerp. Depending on your project, you may want to increase of decrease this value. I found that 100ms is a good average.</li><li><strong>window type</strong>: I will explain this one in details in the next part.</li><li><strong>ratio, offset and log scale</strong>: those are applied to the value you get from the audio listeners to have something visible.</li></ul><p>Increase the ratio to expand the range and be able to get taller images. It will press the value below 0 so you have to increase the offset at the same time.</p><p>I suggest you always have the log scale checked to get something visible and nice, but you may have a specific project where this is something you want, so it’s up to you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*HiUNPFO5mKgXr0F21FqOIw.png" /><figcaption>Audio wave form inspector</figcaption></figure><h4>Visuals configuration</h4><p>Once you configured the audio wave, you can focus on the<strong> ramp texture</strong>. I provided some samples for you, so start by assigning them one after another to see what you can do with it: one or multiple color, smooth or not. You also can change the <strong>filtering </strong>mode of the texture and if you want the frequencies values be <strong>smoothen </strong>one with the next one.</p><blockquote>All those changes must be made outside of Play mode !</blockquote><p>If you increase the texture size, it will use more CPU, but you will get a more detailed audio wave form. I usually limited myself to 128x512 to avoid getting too many areas with nothing (depends on the ratio and offset).</p><p>Last setting you would like to change is the image list. Those are canvas images and the same texture will be output to all images. In the sampe scene, I created a second image which is inverted on the Y axis and a grey color to darken the result, I like it that way.</p><figure><img alt="audio wave form generated from live audio source in Unity" src="https://cdn-images-1.medium.com/max/474/1*6IO8k1V1m2DFfmLBl3x3kQ.gif" /><figcaption>audio wave form generated from live audio source in Unity</figcaption></figure><h4>Window type</h4><p>To make it simple, the window type is what allows to study the audio waves using the Fourier transform and filtering the detected frequencies.</p><p>The window word is used as we filter out some of the audio wave by focusing on specific parts of the audio wave. This is required to prevent some errors generated by the Fourier transform knowned as spectral leaks. I won’t go into further details here but you can find a lot detailed information on the internet if you want to dig.</p><p>Just know that the Hann window type (also known as Hanning window type due to the proximity with the Hamming window type) is good enough in most of cases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*1jVRe-ben_xx_raCiLQeXQ.png" /><figcaption>different window type of the audio frequencies</figcaption></figure><p>Again, experiment on your project to check the result and select the one that fits your use case.</p><h4>Conclusion</h4><p>I wanted to share this asset I made a few years ago because it’s a cool way to visualize audio and I created it because I saw no one else making this simple tool go public.</p><p>The project is available here : <a href="https://github.com/FredericRP/AudioWaveForm">https://github.com/FredericRP/AudioWaveForm</a></p><p>If you learned something, find it cool or just want to say you read this post until this point, just clap once or twice and it will make me happy!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3127419455c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Improved Unity Editor: Dynamic Enums!]]></title>
            <link>https://medium.com/@FredericRP/improved-unity-editor-dynamic-enums-e03316f2c16d?source=rss-68ea6eb92824------2</link>
            <guid isPermaLink="false">https://medium.com/p/e03316f2c16d</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[free]]></category>
            <category><![CDATA[editor]]></category>
            <category><![CDATA[tools-for-design]]></category>
            <dc:creator><![CDATA[FredericRP]]></dc:creator>
            <pubDate>Thu, 07 Mar 2024 17:15:45 GMT</pubDate>
            <atom:updated>2024-03-07T17:15:45.476Z</atom:updated>
            <content:encoded><![CDATA[<p>Among all the packages I have created for Unity, I like this one a lot, and yet, it is almost the last one I created to help me and others. When you design in Unity, an issue that is often raised is how to <strong>link the design data </strong>from documents, sometimes done with online sheets, <strong>to objects and scenes</strong> inside unity.</p><p>Then, you have to use it in your prefabs, editor tools, etcaetera. But how can you both have <strong>optimized code and intelligible data</strong> in the editor? In other languages you have dynamic enum and other sorts of things, but not here. There’s also tools that generates code from a list of strings like the localization tools, but they are still hard to use.</p><p>This tool, packaged under the name <strong>String Data List,</strong> helps answer that: you can code with simple integers and design using a list of strings inside the editor, like the sample below.</p><figure><img alt="unity editor using string data list" src="https://cdn-images-1.medium.com/max/451/0*WOLpm89TtjFFkhCz.jpg" /><figcaption>animals are stored as integers but edited as a limited string list</figcaption></figure><h4>How does it work ?</h4><p>First, there is the list: a simple text file containing one string per line.</p><figure><img alt="text file with names of animals" src="https://cdn-images-1.medium.com/max/108/0*y9AjsWLhKr5LQqZj" /><figcaption>text file content</figcaption></figure><p>Then, you have to link the list with a field or property in your MonoBehaviour. I chose to create the <strong>Select</strong> attribute to do that (like the SELECT tag in old html for dropdown lists). It takes one string parameter matching the text filename. It acts as the ID of the data list.</p><figure><img alt="Serialized field and select attribute" src="https://cdn-images-1.medium.com/max/170/1*WRWteqGDdpp1zcl5Zv2AZw.png" /><figcaption>Select attribute usage (sample with a string property)</figcaption></figure><p>The <strong>SelectDrawer</strong> takes it from there. It uses the string parameter to load the text file and replace a standard integer field or a string field by an enum list, it’s as simple as that!</p><p>Well, it could be. But it takes into account other cases too: the integer property can be a string property, the drawer adapts itself.</p><p>It also displays a red X button to reset the value of the field: <strong>-1</strong> for an integer, and <strong>null</strong> for a string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*1IYlO65_tdIJZFSdCpqWaQ.png" /></figure><p>Also: it manages errors. If the text file does not exists and contains nothing, the property displays the default editable field from the detected type.</p><p>And last, but not least: you can add a second parameter to display a warning if an error is detected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/317/1*l3bd0Es69PC_AUrhH_CdXg.png" /></figure><h4>The DataList attribute</h4><p>And even then, it was not enough. In fact, the first need I had was to display a list of names instead of list of “element + index” in front of a list, even for elements that do not have a string name property as their first one.</p><p>But I faced an issue here: how to have a drawer for the entire list instead of having it for each item? If you ever tried it, you know that an attribute in front of a List is called for each item and not the list itself, so I had to find a workaround.</p><p>My workaround is to use a generic <strong>DataList&lt;T&gt;</strong> that encapsulates the list itself. For convenience, I defined an indexer operator to call the internal list indexer, and a Count property also.</p><p>This way, you can have a <strong>DataList&lt;Animal&gt;</strong> and use it like you would have use the standard <strong>List&lt;Animal&gt;</strong> with indexer and count. In fact, you’ll have to create an <strong>AnimalList </strong>which extends the DataList&lt;Animal&gt; as Unity is not able to serialize generic type (yet?), but it’s one line of code for the whole project usage.</p><p>In the Unity editor, it will look like below. In this sample, we use the same text file as shown at the beginning of this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*_iQdKL4sTO_qUFTw_pjZcw.png" /><figcaption>a list of animals</figcaption></figure><h4>Want another fancy feature? I have two!</h4><ul><li><strong>Multiple files</strong>: you can have multiple files with the same name in different Resources/datalist folders. The names will all be added in the enum list. Convenient for string properties (for instance, you want to split different types of animals and sometime being able to select from all of them), it can be risky with integer properties as there’s no guarantee on the loading order!</li><li><strong>Multiple ids for select</strong>: you can choose to load multiple files for one field with a select attribute. It allows you to have distinct names, for instance names of vegetables and fruits, then a property where you would have both, you can simply tell it to use both! Like the previous one, it’s dangerous to go al.. erh, no.. to use an integer here.</li></ul><h3>Available freely on openUPM</h3><p>Now, you may want to use this <strong>String Data List</strong> package in your projects, I sure do. To use it widely in mine, I’ve imported it in the openupm package repository. To import any of the tools I wrote available on <strong>OpenUPM</strong>, follow the steps below.</p><h3>1. Add openUPM as a scoped registry in unity</h3><p>From the project you want to add your package to, go to your <strong>project settings</strong>, in the section named <strong>package manager</strong> where you can add a scoped registry.</p><p>From the same registry, openUPM, you can add multiple scopes if you find other useful assets there, so be sure to add every scope you want to so Unity will search for them at the right place. Set the name as you wish, I just use OpenUPM. Set the URL to <a href="https://package.openupm.com/">https://package.openupm.com</a> then start by adding “com.fredericrp”, then apply.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*k6fj5rZQyT4N_tq2.png" /></figure><p>Add a scoped registry in the project settings</p><h3>2. Import the package from the Package Manager</h3><p>Once it’s done, you will see the matching registries in the unity package manager, under the section “<strong>My Registries</strong>”: my packages are grouped under the name “FredericRP”. Like any other package, you can install, update and remove the packages directly here, and they will appear under the “Packages” folder of your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*aZU4ZjoWe5Ac8Wep.png" /></figure><p>Find the <strong>String Data List</strong> and others packages right there!</p><p>This is one of the many tools I share on openUPM, follow me to understand and know all the others tools I share and follow my journey with unity!</p><p>If you liked this article, I let you applause or comment it, and thanks for reading up to this very end!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e03316f2c16d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Order to Chaos: mastering randomization with the Bucket technique]]></title>
            <link>https://medium.com/@FredericRP/from-order-to-chaos-mastering-randomization-with-the-bucket-technique-b1717885ea08?source=rss-68ea6eb92824------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1717885ea08</guid>
            <category><![CDATA[script]]></category>
            <category><![CDATA[bucket]]></category>
            <category><![CDATA[bucketlist]]></category>
            <category><![CDATA[bean-bag]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[FredericRP]]></dc:creator>
            <pubDate>Thu, 22 Feb 2024 11:53:11 GMT</pubDate>
            <atom:updated>2024-02-22T11:53:11.102Z</atom:updated>
            <content:encoded><![CDATA[<p>A <strong>bucket</strong>, also called <strong>bean bag</strong>, is the easiest way to transform an ordered list to a randomised list where you never encounter twice the same object. In fact, this is almost the most used asset I use in my projects, maybe you should too if it’s not the case yet, let’s dig into the how and why.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9V-z5upSAyq65E2p9Mhh0g.jpeg" /><figcaption>Which marble will I pick after? (Imagined by me, created with AI)</figcaption></figure><h3>Why use it</h3><p>Let say you have a deck building game: surely you have created some smart way of adding cards to the deck, and at the right moment, you have to decide in which order the cards will be in the deck during the gameplay. Or let say you have a runner, and each part of the path is a prefab you have to instantiate in the scene. Then, you must decide what is the next prefab to instantiate.</p><p>There are multiple ways to do it, one of them could be to list the prefabs that can go after another, so you control the design of the path, ensure there is no issue when two prefabs follow one another. Or, if it’s a simple prototype, just choose the prefabs from a list of prefabs. In both situations, you have to get one prefab from the whole list of prefabs, wether it be all of them or a set of them.</p><p>The easiest way to do it ?It is by getting a random prefab from this list. Now the random method has two main issues:</p><ul><li>it can give you multiple times the same number but letting away some other, giving a non-linear distribution that can be annoying for the player</li><li>it is not reliable from one platform to another: having some correct randomised values on the unity editor will not be replicable on mobile or console (after all, it is a random value).</li></ul><p>That is why a bucket is helpful: it allows you to get exactly one time each number of a list, with a randomized order. This way, all your prefabs will be used once before the player gets another time the same prefab.</p><blockquote>Note that if you would like to have multiple times the same prefab, you can use multiple numbers linked to the same prefab, like a weighted list.</blockquote><h3>How to use it</h3><p>This tool is extremely simple, there are three phases for a bucket:</p><ul><li>generate</li><li>randomize</li><li>pick</li></ul><h4>1. Generate</h4><p>Create a new Bucket and set the number of values you want to get from it. During the creation process, it generates a list from 0 to this number minus one (it’s C# so list indexes start at 0). Use the code below, once you have imported the package (see at the end of the article), for a sample of 25 random numbers.</p><pre>import FredericRP.BucketGenerator;<br>// ...<br>var bucket = new Bucket(25);</pre><h4>2. Randomize</h4><p>It is done internally: from the generated list, the bucket randomises the order of the list before the first call.</p><p>There is no code to do that as it’s automatically done on the creation of the class.</p><h4>3. Pick</h4><p>Then, each time you want a randomized number, retrieve it from the bucket, it gives you the current number from the list, takes it out and go to the next one. Simply call the <strong>GetNumber </strong>method as shown below.</p><pre>var myRandomNumber = bucket.GetNumber();</pre><p>Those simple steps are shown in the picture below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*IHxDsBNxgQhy3KEc.png" /><figcaption>the bucket usage in three steps: generate, randomize, pick</figcaption></figure><p>Once all the numbers are given, it starts all over. If specified it during the construction phase, the list is <strong>randomized again</strong> when the index is reset, so you get the impression it is truly random.</p><p>To simplify and optimize the bucket, the list is generated once and we store only the index in the list. Once the index reached the end of the list, it is reset to zero.</p><blockquote>Beware that when you reach the end of the list, the random process can make the first item being the same one as the last one from the previous generate phase, so you can have in this particular context twice the same number in a row!</blockquote><h3>Bucket Generator as a package</h3><p>Like the others tools I share, this one too is available in a open source package available in the openupm package repository. To import any of the tools I wrote available on <strong>OpenUPM</strong>, follow the steps below.</p><h3>1. Add openUPM as a scoped registry in unity</h3><p>From the project you want to add your package to, go to your <strong>project settings</strong>, in the section named <strong>package manager</strong> where you can add a scoped registry.</p><p>From the same registry, openUPM, you can add multiple scopes if you find other useful assets there, so be sure to add every scope you want to so Unity will search for them at the right place. Let’s start by adding “<strong>com.fredericrp</strong>”, then apply.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*J8liKch_FqI27tHr.png" /><figcaption>Add a scoped registry in the project settings</figcaption></figure><h4>2. Import the package from the Package Manager</h4><p>Once it’s done, you will see the matching registries in the unity package manager, under the section “<strong>My Registries</strong>”: my packages are grouped under the name “FredericRP”. Like any other package, you can install, update and remove the packages directly here, and they will appear under the “Packages” folder of your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*rmH907lkdbPNaL9d.png" /><figcaption>Find the Generic Singleton and others packages right there!</figcaption></figure><p>This is one of the many tools I share on openUPM, follow me to understand and know all the others tools I share and follow my journey with unity!</p><p>If you liked this article, I let you applause or comment it, thanks for reading it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1717885ea08" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Replace placeholders by awesome sprites with AI in 3 steps]]></title>
            <link>https://medium.com/@FredericRP/replace-placeholders-by-awesome-sprites-with-ai-in-3-steps-73083eadd060?source=rss-68ea6eb92824------2</link>
            <guid isPermaLink="false">https://medium.com/p/73083eadd060</guid>
            <category><![CDATA[videogames]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <dc:creator><![CDATA[FredericRP]]></dc:creator>
            <pubDate>Fri, 09 Feb 2024 14:07:18 GMT</pubDate>
            <atom:updated>2025-12-16T09:39:09.743Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*rXAkQCyKJhq2XbILLWxpkQ.jpeg" /><figcaption>UI Placeholders on the left, generated sprites on the right, and the background obviously</figcaption></figure><p>When I prototype new games, I usually create placeholders for the first iterations until I have a playable version I’m happy with. And as I’m coder and no artist, even when I create those placeholders, they are ugly rectangles or circles. But what if I could get good looking placeholders?</p><p>Follow me on this journey where I explore and show the path by using generative AI to remove the need of placeholders.</p><h3>1. The description</h3><p>First, you need to know what you are looking for. For instance, let say we want to have some UI sprites and also some flowers for the game itself. You can easily find some game assets prompts in the internet to start with, then try for yourself some modifications to get something near what you want. One key element in the prompt is to specify you want a <strong>spritesheet </strong>or<strong> asset sheet </strong>and <strong>isolate on white background </strong>(or another color if your game has a specific overall color, but white is good for general purpose).</p><p>For this sample, I used this prompt:</p><pre>game asset sheet, flower top view, in the style of detailed character illustrations, 2d game art, hyper-realistic details, rounded shapes, bright colors, bold shapes, subtle gradients, Tim Shumate, isolate on white background, cinematic lighting, disney style</pre><p>My favorite tool here is Midjourney, I tried others generative AI for images but never got near the same global quality and variations on sprites than I got from Midjourney. That may change in the future as lots of newtools are published every week (or every day I may say).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*XJSOHOONMB3amei12LOh8w.png" /><figcaption>Flowers spritesheet</figcaption></figure><p>Oh, here is one last tip for this part: by using the <strong>exact same prompt multiple times</strong>, you can have veeeeery different results, so don’t hesite to hit the retry button tons of times to get what you like! (it may not be the case with specific prompt on MidJourney 6, but that’s a different story).</p><h3>2. The path to the unique sprite</h3><p>Now that you have a <strong>spritesheet</strong>, it’s time to slice it! I studied more than 15 development languages in my past, but I’m new to Python, so I’m still learning, and don’t know how to do file and picture manipulation with it. But it’s easy to setup a python environment on any computer and launch the code in a few steps, so I went for it… and asked chatGPT to write the code for me!</p><p>First time, I only asked to load the spritesheet, then slice it by using the number of sprites on it, as an array with columns and rows. Obviously it was not good enough as the generative AI is not creating a perfect grid with sprites on it. So I upgraded the code to use a DFS (Depth First Search) algorithm: as soon as there is a colored pixel, start from it and extend the region until you got all colored pixel, then cut it, write it in a PNG file and search for the next one.</p><p>It…was… extremely easy… and powerful to slice the spritesheet that way!</p><p>But wait, those PNGs files.. they have sprites with white background on it, not useful at all!</p><h3>3. Full disclosure</h3><p>I was wondering what would be the best way to remove the background from the image, then obviously remembered the <a href="http://remove.bg/">remove.bg</a> website that do just that for any photo, that could do it for sprites also, right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/1*ZqJQtIzpWT3HtcCcgZULsw.png" /><figcaption>Each month, 50 previews are offered</figcaption></figure><p>Well, yes. They even have an API you can call from command line with 50 low resolution tries per month (they call it “free previews”). Again asking chatGPT to use this API to make the spritesheet transparent before slicing it (of course you use the API before slicing it, otherwise it would consume a lot of API calls for nothing) and… That’s all!</p><p>By using two different generative AIs + an online AI tool, you now have a tool to generate unique transparent sprites for your prototype with only one method to call.</p><p>I was astonished on how easy that was, and I’m sure someone has done a tool from it by now, but until that, you can find the SpriteSplitter script in <a href="https://github.com/FredericRP/SpriteSplitter">this repo on my github</a>.</p><p>Cheers,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*zfmnRFtVh_9XbCkcZntrEA.gif" /><figcaption>a prototype with generated sprites</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73083eadd060" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elevate User Experience: use Transition Screens in your games!]]></title>
            <link>https://medium.com/@FredericRP/use-transition-screens-in-your-games-unity-f8742fea219b?source=rss-68ea6eb92824------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8742fea219b</guid>
            <category><![CDATA[transitions]]></category>
            <category><![CDATA[interfaces]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[FredericRP]]></dc:creator>
            <pubDate>Fri, 19 Jan 2024 11:07:13 GMT</pubDate>
            <atom:updated>2024-01-24T19:35:03.607Z</atom:updated>
            <content:encoded><![CDATA[<p>Between scenes, hiding loading times or simply making a visually smooth transition, the “transition screen” is a must have. In the open source toolset I share on OpenUPM, the screen transition package contains scripts and multiple prefabs allowing you to manage such screens in a reliable and flexible manner. Let see why they are important, how to use them and how to improve them!</p><figure><img alt="Using a “transition screen” to hide the loading process in a game" src="https://cdn-images-1.medium.com/max/1024/0*LqGwYk4zjazvxgSb.jpg" /><figcaption>Typical screen transition steps</figcaption></figure><h3>Why screen transitions are important</h3><p>First: <strong>feedback</strong>. Remember you have to show to the player something is happening even (and especially) when he does not interact. I’m not speaking about cut-scenes here, but rather loading something: a new level, a shop, a lobby, or any other stuff that could take some time preventing the player to act and get immediate feedback on its action.</p><p>Second: <strong>immersion</strong>. Yes, that’s true. One of the first transition screen I remember was the one from Resident Evil when you go through a door. It was an intelligent way of hiding the level loading behind an immersive transition screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6sM3M4Z3A6njz-hK" /></figure><p>Third: <strong>design</strong>. It can be used as a design tool: to lower the pressure on the player, push him some vital information on the game, beeing a narrative, matchmaking workflow, or anything else.</p><p>In one of our games, this screen was also used to hide the procedural generation time required for the next level to be created. The first algorithm was so fast that it was easy to hide it using any UI animation, but finally, after some refining to get interesting levels, the duration was too long for it to be hidden only this way. We added a transition screen that act in three steps:</p><ul><li>show the transition screen to hide everything else</li><li>send an event so any required function can be called, like generating a level</li><li>once everything is setup, hide the transition screen.</li></ul><h3>How to create them?</h3><p>You can do it on your own, use existing assets, or take inspiration from existing assets then create your own. Luckily for you, I now share what we used in numerous games created for mobile, kinect app or consoles. So I will talk now about a unity package, consisting mainly in one prefab that you can just put in your scene.</p><p>What I advise you to do is to put this prefab in the early stages of your game loading workflow. I discovered that four scenes is the best way of handling the full loading of a game, see my <a href="https://medium.com/@FredericRP/four-scenes-template-ffe38a7043f5">specific post</a> on that.</p><p>Once the prefab is present, you’ll notice that it has its own Canvas configured to be on top of others. You may have to check if this suits your needs.</p><p>Then, simply call the <strong>Transition.Show()</strong> static function to launch the animation that will cover the whole screen.</p><p>The event configured by default in the prefab will be called, so if you want to do something special when everything is hidden, subscribe to this event. You will find a sample in the package so you can perfectly understand how to do it. And I will also soon have a dedicated event management post for you describing the whole process.</p><p>In the sample, I also use the <strong>EasyLoading </strong>package that is meant to smoothen asynchronous loading of scenes in Unity (it’s pretty straight forward but if you think a post would be useful, ask me! ). So by default, you only have to enter the scene name in the prefab, and nothing else.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*-OeWu62DUbbvdJCmYo5sNA.jpeg" /><figcaption>Inspector of TransitionToScene with sceneName, async, loading trigger and loading event parameters</figcaption></figure><p>This package allows to display a nice loading gauge on the screen, so the player knows something is happening. Once you have handled whatever you want in your workflow and the new scene is ready to be activated, either you use the default setting and it’s done automatically, either your workflow requires more processing power, and you may have to postpone the scene activation. In this case, you will have to call the function on the <strong>LoadScene </strong>script to activate the new scene.</p><h3>Cosmetic</h3><p>In the ScreenTransition package, I share two different prefabs for the transition:</p><ul><li>with moving images</li><li>with a gradient shader</li></ul><h4>Moving images</h4><p>This one animates images on the Canvas to get a nice animated transition. You can customise it with your own colors to get the result you want. It can be good to use black colors to get a full black screen at the end of the animation, it renders usually best on small screens and the player understand well it is a transition screen in this case, but it’s up to you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*EzJLEZ63hbZF0rX_MHBoRQ.gif" /><figcaption>The transition ending with moving images that overlap the screen</figcaption></figure><h4>Gradient shader</h4><p>This one uses two images and a color: one that will be displayed full screen during the transition, and another special one that is use for the transition effect. The gradient image is only black and white and all values between full black and full white create the transition effect. Here are some samples to show you how it renders.</p><p>As the other prefab, you can customise this one by using your own images to get an awesome transition!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/0*9_0KoIl34I-eqhKK.gif" /><figcaption>Circle transition a little like Animal Crossing</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/415/0*25CyvavS8TtkmFXH.gif" /><figcaption>Diamonds grid transition</figcaption></figure><h3>Screen Transition as a package</h3><p>Now, you may want to use it in your projects, I sure do. To use it widely in mine, I’ve imported it in the openupm package repository. To import any of the tools I wrote available on <strong>OpenUPM</strong>, follow the steps below.</p><h3>1. Add openUPM as a scoped registry in unity</h3><p>From the project you want to add your package to, go to your <strong>project settings</strong>, in the section named <strong>package manager</strong> where you can add a scoped registry.</p><p>From the same registry, openUPM, you can add multiple scopes if you find other useful assets there, so be sure to add every scope you want to so Unity will search for them at the right place. Set the name as you wish, I just use OpenUPM. Set the URL to <a href="https://package.openupm.com/">https://package.openupm.com</a> then start by adding “com.fredericrp”, then apply.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*J8liKch_FqI27tHr.png" /><figcaption>Add a scoped registry in the project settings</figcaption></figure><h4>2. Import the package from the Package Manager</h4><p>Once it’s done, you will see the matching registries in the unity package manager, under the section “<strong>My Registries</strong>”: my packages are grouped under the name “FredericRP”. Like any other package, you can install, update and remove the packages directly here, and they will appear under the “Packages” folder of your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*rmH907lkdbPNaL9d.png" /><figcaption>Find the Transition and others packages right there!</figcaption></figure><p>This is one of the many tools I share on openUPM, follow me to understand and know all the others tools I share and follow my journey with unity!</p><p>If you liked this article, I let you applause or comment it, and thanks for reading up to this very end!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8742fea219b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A tool to share your own Unity packages with openUPM]]></title>
            <link>https://medium.com/@FredericRP/a-tool-to-share-your-own-unity-packages-with-openupm-e1a9e4c3c33a?source=rss-68ea6eb92824------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1a9e4c3c33a</guid>
            <category><![CDATA[free]]></category>
            <category><![CDATA[package-management]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[tools]]></category>
            <dc:creator><![CDATA[FredericRP]]></dc:creator>
            <pubDate>Fri, 27 May 2022 13:12:21 GMT</pubDate>
            <atom:updated>2022-10-27T21:24:36.800Z</atom:updated>
            <content:encoded><![CDATA[<p>Two years ago, I wrote about how to manage your own assets in the unity package manager. That was not an easy task nor very user-friendly, so it had to be upgraded. A good point that I started then was to split the packages, allowing them to have a unique git repository each.</p><p>We also saw a good move from Unity for developers: they dropped the usage of the asset store for assets management, and use the package manager instead (at last)!</p><p>The core of sharing packages is to be able to both have autonomous groups of code and code and/or assets that you can use in multiple projects.</p><p>So, let’s see what the new workflow is:</p><ol><li>update a package on github (openupm workflow is plugged to github)</li><li>setup the package on openupm</li><li>add openupm as a scoped registry in the project settings.</li></ol><h3>Update the package on GiT</h3><p>I won’t offend you by explaining how to set up a git and commit on github, but you still need to follow some guidelines.</p><p>For the package to be usable in the package manager, you have to create a<em> </em>file named <em>package.json</em> on the asset folder that suits the <a href="https://docs.unity3d.com/Manual/upm-manifestPkg.html">package.json template</a>, see a sample below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*hikU9HoJLfnzQ7U96gA7gA.png" /><figcaption>package.json of the persistent data system</figcaption></figure><p>A good practice is also to have both README.md and CHANGELOG.md files at the root of your folder so it’s easy for everyone (you, your team, the other developer that would find your package) to know what your package can do, and the…well, changelog. The readme file is also used to select a default preview image for the openupm package browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*Uv3gmUC67EnaFXBGBBH8Wg.png" /><figcaption>Changelog sample</figcaption></figure><p>So, you have your code and assets correctly structured as a package (see <a href="https://medium.com/@FredericRP/your-assets-in-the-unity-package-manager-from-a-git-subfolder-1339880dd09f">my previous post</a> for details) and you committed everything on github, with a tag on it.</p><p>Once it’s done, you can add the package manually in Unity, but it’s not enough.</p><h3>Setup the package on OpenUPM</h3><p>Go to <a href="https://openupm.com/">openupm.com</a> and fill the form: repository name, branch, select the package.json file if it’s not selected by default (useful when in a subfolder), readme and license. See below the first step: once you entered the repository URL (of course, it has to be public!), clicking on the <em>Go</em> button makes openUpm search for details and files in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*VqPY1nMtMKIq0OJ_ADCUQQ.png" /><figcaption>submit a new package to openUPM</figcaption></figure><p>If you have an unusual setup you can also filter on the package name, add a prefix for the version tag, and even a minimum version to build.</p><blockquote>You can select a preview image at this step but I advise you not to do so as it’s easier in the update process to update the image in the readme file than update the openupm description.</blockquote><p>Once the form is filled, you will have to complete the workflow and wait for the nightly process to be done before you can see the package from unity and see it in the openUPM package registry.</p><p>But right now, you’re done with openUPM, the rest will last forever and you won’t have to go back here for a while.</p><h3>Add openUPM as a scoped registry in unity</h3><p>The final step of this new workflow: from the project you want to add your package to, go to your <strong>project settings</strong>, in the section named <strong>package manager</strong> where you can add a scoped registry.</p><p>From the same registry, openUPM, you can add multiple scopes if you find other useful assets there, so be sure to add every scope you want to so Unity will search for them at the right place.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*49F-SQeB46axBg8VwexWcw.png" /><figcaption>Add a scoped registry in the project settings</figcaption></figure><p>Once it’s done, you will see the matching registries in the unity package manager, under the section “<strong>My Registries</strong>”. Like any other package, you can install, update and remove the packages directly here, and they will appear under the “Packages” folder of your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*UqFfMp44BN8OfitvbT8qcw.png" /><figcaption>All my shared packages at my hand!</figcaption></figure><h3>My free tool for you: Unity Package Tool</h3><p>Yet, another issue bothered me here: I don’t have any CI/CD workflow for those assets, mainly when I update the version of one package and use it in another one.</p><p>With multiple assemblies, I can tell Unity what other package is required so the compile process just works. And with the version name in the package.json file, you can specify the exact dependencies and that is used by the package manager to search, download or update the other packages automatically.</p><p>But <strong>how can I link those two together</strong>? By default, you can not.</p><p>Good news: with the <a href="https://github.com/FredericRP/UnityPackageTool">UnityPackageTool</a> I made, you are only one click away to get that.</p><p>What does the tool is:</p><ol><li>create a list of assembly definition files from the packages in the project</li><li>list the packages.json files and their matching runtime assemblies</li><li>for each package found, update the dependencies from the assembly definition by finding the matching version in other packages.json or the unity package.</li></ol><p>The last one was a little tricky as we have to use all assemblies known in the unity project and use an asynchronous API from the package manager, then find the version with the assembly name that matches the following format:</p><blockquote>&lt;com.package.name&gt;@&lt;version&gt;</blockquote><p>Finally, you only have to click on “<strong>Update dependencies</strong>” from Window/FredericRP to update all packages.json files in your project to have the correct dependencies (package name and version) found from the assembly definition file!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*lFsQ1cPP4HUSwMDrhOW29Q.png" /><figcaption>Window / FredericRP / Update dependencies</figcaption></figure><p>Understand I needed that tool because I have multiple packages working together. For instance, the <strong>GameQuest</strong> package uses a lot of other packages like <em>EventManagement</em>, <em>Singleton, </em>and <em>TextMeshPro</em>, so when I update it, I want to make sure everything is synchronized. I also use the updated version of them and sometimes I update other packages from the needs I have in the main one.</p><p>With this tool, I don’t have to bother if there was another update in the project: it just fixes the package.json file of the asset I want to commit!</p><h3>Pros and Cons</h3><p>On the good side, this setup allows sharing packages with other projects and making sure they have the correct dependencies with only one click. You can also check it’s working well by checking your package page, on the build pipelines section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*pP45uvZsEmADqDneHXN3XA.png" /><figcaption>Build pipelines on openUPM</figcaption></figure><p>On the downside, this prevents you to fix an issue or make any upgrade of the codebase from the project where the package is added: packages imported like this are read-only, so you will sometimes have to upgrade your package in your source project, then wait for the night process to have it available from the package manager. But I have a schedule that allows switching to another task if a package has to be updated for new needs or fixes.</p><p>That way was the easiest way I found to share packages through multiple projects and make them available for everyone. As mentioned before, you can find my packages, and of course this tool, from <a href="http://github.fredericrp.com/">github.fredericrp.com</a> and openupm.com by searching for “<strong>fredericrp.</strong>” packages. Let me know if you think this is overkill and/or if you find that another way is better!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1a9e4c3c33a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Four scenes Unity project template]]></title>
            <link>https://medium.com/@FredericRP/four-scenes-template-ffe38a7043f5?source=rss-68ea6eb92824------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffe38a7043f5</guid>
            <category><![CDATA[design-tools]]></category>
            <category><![CDATA[free]]></category>
            <category><![CDATA[project-template]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[FredericRP]]></dc:creator>
            <pubDate>Wed, 07 Oct 2020 17:46:58 GMT</pubDate>
            <atom:updated>2022-10-27T21:26:39.435Z</atom:updated>
            <content:encoded><![CDATA[<p>When you develop a video game, sometimes you create the prototype, then you think about making it a real and complete game.</p><p><em>Where do I have to optimize it, how to switch from one level to another, hey it’s freezing between the levels, how am I going to make it smooth for the players??!</em></p><p>Well, few assets can make your life easier. The Four scenes project template is one of them, it is free and available from the end of this post. Here’s why it’s so useful.</p><p>This asset was created as a legacy from the indie games studio I created in 2012. These are not the exact same sources as the one used during its 6 working years, but an evolution of those.</p><h3>Why four scenes?</h3><p>When your Unity game is launched, the OS has to load the Unity engine first. While it’s doing so, you only have the splash screen shown, that is your logo and/or the Unity logo, with a little animation if you’re lucky.</p><p>After that, your first scene is loaded, and every shared resource is also loaded. Once they are loaded, all game objects of your first scene are activated, and all Awake and Start and OnEnable methods are called and executed.</p><p>Only after all that has happened, the first scene is displayed to the player. That can be a <strong>loooooong time</strong>, believe me! If you build an iOS game, it can even cause your app to be killed by iOS because it’s taking too long before showing anything to the user (been there..).</p><p>So the solution is to split your first scene into pieces, but not only in two pieces. Here are the scenes I put in every project I developed once I understood that.</p><h3>The first scene: static loading</h3><figure><img alt="A blurry image as second slash screen" src="https://cdn-images-1.medium.com/max/957/1*k8LEJZSaEAoojIo-1MRalQ.jpeg" /></figure><p>The first scene has to be <strong>minimalist</strong>: think about another splash screen and one script. This is your entry point, to tell the player and the OS that the engine has been loaded and this is the game going on now.</p><p>This scene is there to take the player one step further: you can have an animated splash screen, detect the hardware performance to redirect toward the SD or HD quality settings, but that’s all.</p><p>In the template, there’s a canvas and a blurry background image. Nowadays, it’s not as required as before, but it’s a trick for low-end devices: use a <strong>blurry image</strong> with a lower resolution to use less memory and improve performance.</p><p>There’s only one custom script and it’s there to load the next scene.</p><p>I don’t add custom shader, fancy code nor specific very optimized code when it’s not required.<br>Since my first coding project a while ago, and specifically, since 2007 when I started to use Unity, just using correctly the engine or development environment is the correct answer.</p><h3></h3><p>Also, if you want to make a game, on whatever scale or level, I will always encourage you to choose the tech you are the most comfortable with.Don&#39;t go for a tech just because everyone told you how fancy it is.Use what makes you have fun. That&#39;s what actually matters.</p><p>Like Thomas said: <strong>use your favorite tools!</strong></p><p>And I also add: use and learn them until you can’t learn anymore, only then you will be able to get the most out of them.</p><p><strong>Minimalist</strong> is the keyword here.</p><h3>The second scene: asynchronous loading</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*CLcGQqvvFco2oBqpPziy_Q.jpeg" /><figcaption>asynchronous loading allows displaying a progress bar</figcaption></figure><p>In the second scene, we go a little fancier: we load a transition UI and an asynchronous loading script that allows displaying a loading progress bar to the player!</p><p>The <strong>Transition is a prefab</strong> and a singleton from my <a href="https://store.fredericrp.com/">Standard Assets</a> that exists in two flavors: a transition with animated panels, and a cut-out image with a specific shader.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*RIJcz_rSpcG31Gvh4sVy5g.gif" /></figure><p>The loading script is improved to handle the transition prefab to be shown when the scene is loaded but before it’s activated. Once activated, the transition will be hidden automagically. Bless the event handler (also included in the Standard Assets package). Of course, the progress bar is updated from an event triggered by another script that monitors the scene loading operation.</p><p>I’ve also added a tips manager so the player starts to see something interesting: he can learn something and is not bothered anymore by some logo or still screen.<br>Tips are included in text files that are exported in Asset Bundles.</p><p><em>Those are not yet managed as remote assets in the demo, but this will be included in a future release.</em></p><p>Still, this scene is quite simple but allows us to climb one more step.</p><p>From that scene, the player is not waiting anymore in front of a static screen, and we can break on through to the other side…🎵</p><h3>The third scene: data loading</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*3Dg5JRPtaVR6kbh4XKBkFg.png" /><figcaption>An object pool to preload some data</figcaption></figure><p>This scene can be the first huge scene in your project (well, be careful there). If you have large assets that will be used in every other scene of your game, this is the scene where you have to put them. In the template, I’ve included an <strong>object pool</strong> with some sample assets, just to show you how to handle them.</p><p>Music, audio sources, resources, and every game-specific checking script you want to do can happen here.</p><p><strong>Remember</strong>: when this scene is displayed, that means that <strong>everything</strong> in this scene has already been loaded!</p><p>And the last advice but not the least: this scene is the last one that will be loaded only <strong>once </strong>in your game. Every asset loaded here won’t be loaded again, and you <strong>must never go back to this scene</strong> from your game.</p><h3>The fourth scene: menu</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*KBBGQrysb1pzAOXjrGWgiQ.gif" /></figure><p>This can be replaced by any scene you want, but a lot of games have a menu so I decided to include one here. This is a simple main menu scene with an animated play button. To use it right away, search for the object named <strong>PlayButton</strong> and change the <strong>scene name</strong> to whatever you want to load after this one. By default, this loads the <em>game</em> scene.</p><p>In the menu, I’ve included some fancy stuff :</p><p>- scrolling tiled image in the background<br>- animated play button<br>- vignetting using a simple foreground image</p><h3>Test it</h3><p>Packages are available free from my <a href="https://github.com/FredericRP/FourScenesTemplate">GitHub repository</a>.</p><p>To use those four scenes, just include them in the correct order in your build settings: they are prefixed by a number so it should not be that hard.</p><p>This template uses some of my other free standard assets, available from the Unity asset store and from my <a href="https://github.com/FredericRP">GitHub repositories</a> also.</p><p>If you decide to use them for a project, a game jam, or anything, tell me if that helped you or if anything can be changed. I will make this template evolve to fulfill my new game projects and could include yours!</p><p>Thank you for reading until here and write to me on <a href="https://fredericrp.com/">FredericRP.com</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffe38a7043f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your assets in the Unity Package manager from a GiT subfolder]]></title>
            <link>https://medium.com/@FredericRP/your-assets-in-the-unity-package-manager-from-a-git-subfolder-1339880dd09f?source=rss-68ea6eb92824------2</link>
            <guid isPermaLink="false">https://medium.com/p/1339880dd09f</guid>
            <category><![CDATA[publishers]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[asset-store]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[FredericRP]]></dc:creator>
            <pubDate>Wed, 10 Jun 2020 09:55:44 GMT</pubDate>
            <atom:updated>2020-06-10T09:55:44.957Z</atom:updated>
            <content:encoded><![CDATA[<p>Since I shut down my video games studio, I managed to rebuild an upgraded version of assets we designed during that time. For my own projects and for others, it’s an easy way to improve games projects quickly, so I started to share them on <a href="http://github.com/FredericRP">github.com/FredericRP</a> and even from the asset store itself, for free.</p><p>With the package manager that is now used for both unity packages and asset store publishers packages, and more and more assets to publish, one question came over and over: how do I make it easy to import only the assets I want, and still manage a simple version control to share to everyone?</p><p>After some thoughts and discussion with fellow game developers, the answer was in fact really simple: I had to change my GiT repository so we could pick what to import in the package manager without the hassle of writing command line. Easier for me to manage, easier for everyone to pick the unique asset they need or the whole package, without the need to split the repository. I faced some issues so I’m sharing here the results of what worked for me.</p><h3>Some rules</h3><p>I wrote some requirements I want to be satisfied:</p><ol><li>still, use my “Standard Assets” repository</li><li>import easily one or multiple assets in any unity project</li><li>no use of third party plugin for the import process</li><li>limit to trusted or known servers (Unity, GitHub, etc.)</li></ol><h3>The starting point</h3><p>The hierarchy I use in the repository replicates the one used in my previous projects: one root folder, and one folder for each asset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/273/1*cfafbCsTGnflPpF00WouGw.jpeg" /><figcaption>Folder hierarchy</figcaption></figure><p>As shown above, I used the special subfolder “<em>Plugins</em>” from only one repository to include it in my unity projects. This special folder allows telling Unity to compile them in an assembly before the others. You’ll notice that will change. From that folder, I exported one package that contained everything. One README file for every asset, and another one in the subfolders that were essentially a copy/paste for their specific paragraph.</p><p>Now, I have to understand what changes need to be done in the <strong>folder hierarchy</strong> and how to<strong> import them in unity without error</strong>.</p><p>You have to know that importing subfolder in the package manager only works from <strong>Unity 2020.1</strong>.a21 BUT was also backported in <strong>Unity 2019.3.4</strong>f1. I tested it in Unity 2020.1.0b7 and 2019.3.5f1.</p><p>For most assets, that should not be an issue to import them in another version of Unity (at least a 2018 release), but if there’s an issue and you have to use a specific version, don’t hesitate to ask me for support.</p><h3>Folder hierarchy changes</h3><p>The subfolder Plugins could remain, that does not matter for now, but I move the images for each asset to their relative “<em>Documentation~”</em> subfolder, which allows me to still have a preview from the GitHub main page and have everything in each asset subfolder.</p><p>For each asset, I have to comply with the <a href="https://docs.unity3d.com/Manual/cus-layout.html">requested package layout</a>: I have to move all scripts and other assets in the “<em>Runtime</em>” subfolder, exception made for the editor assets that need to move in the “<em>Editor</em>” subfolder.</p><p>I already had a <strong>README.MD</strong> file so I just need to update it to use images that are in each asset subfolder and not the root images folder. For now, I also copy/paste it in the subfolder “<em>Documentation~</em>” so the package manager finds it also.</p><blockquote>GiT reads the README on the <strong>root </strong>folder, the package manager requires it in the <strong>Documentation </strong>subfolder.</blockquote><p><strong>Good news</strong>: I wanted to add a changelog but did not really take the time to do it. That is now the right time! And since even Unity suggests it, I will use the “<a href="http://keepachangelog.com/en/1.0.0/">Keep a changelog</a>” advice also.</p><p>That’s it for the new hierarchy.</p><h3>Import in Unity — now comes to the real work</h3><p>I use both bitbucket and GitHub as main online repos, and since I started with bitbucket, I’m used to SourceTree and its GUI. I tried some other GUIs but never managed to have the same amount of satisfaction in both “working tool” and “nice to use”, so I still use it (the fact that I once developed using a mac can matter as it was more stable and errorless on a mac before it did on Windows).</p><p>With SourceTree, the git used is embedded by default, and you still can use it if you want. For authentication, I use SSH private/public keys and the <strong>pageant </strong>software that is included also with SourceTree, so it’s pretty straightforward if you stick with it.</p><p>Unity does not know you are using pageant and is not able by default to use your private key nor ask you to enter the passphrase.</p><p>So you have to tell it, and that means tell Windows where it is, using <strong>one environment variable</strong>.</p><h4><strong>GIT_SSH</strong></h4><p>Set this environment variable to your SourceTree “<em>/tools/putty/plink</em>” executable. <strong>Do not include quotes</strong> in the var, even if the path includes spaces: GiT handles it and it would add unnecessary quotes and break the command line. For instance, mine is set to:</p><blockquote>C:\Users\FredericRP\AppData\Local\SourceTree\app-3.3.7\tools\putty\plink.exe</blockquote><p>Beware that pageant must already be loaded with your key, because you won’t be able to set it nor enter the passphrase from the Unity Package Manager (UPM). That should not be a problem if you work on an everyday basis on your projects as you surely already have pageant launched with the key(s).</p><p>From now on, you can add an asset using its git repo like <a href="http://git@github.com:FredericRP/Standard-Assets.git">git@github.com:FredericRP/Standard-Assets.git</a>, and even specify an asset from a subfolder like /BucketGenerator from the UPM!</p><p>Click add on the package manager and enter the URL below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/1*rOlzn6TeKnWpAopFq5i5Fw.jpeg" /><figcaption>Add package from git URL</figcaption></figure><blockquote>git@github.com:FredericRP/Standard-Assets.git?path=/BucketGenerator</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*99cpIlWWTD8UojqC4k-Miw.jpeg" /><figcaption>typing package to add GiT URL</figcaption></figure><p>Actually, you can check the available assets from the <a href="https://github.com/FredericRP/Standard-Assets">FredericRP Standard Assets GitHub page</a>.</p><p>If you have one asset without any dependency, that’s almost it, the last step is to create a proper package.</p><h3>Assemblies and package</h3><p>This was something I wanted to change since the beginning: each asset should not be compiled each time someone changes one script in its project. The Plugins special folder enables that, but if I want to update one asset, it compiles the whole set. So I decided to create an assembly definition for each asset also. In fact, that is also required when you create a package managed from unity.</p><p><em>I hope that it does not increase the memory footprint somehow but I had no time to check that for now: if you have intel, please share them on the comments!</em></p><p>Each assembly adds a tiny file in each Runtime and Editor subfolder, named after the asset name, be sure to follow <a href="https://docs.unity3d.com/Manual/cus-asmdef.html">those rules</a> also. You only have to click on “<strong>Create / Assembly Definition</strong>” in the correct folder (Runtime and/or Editor subfolder of your package), name the file accordingly and that’s it!</p><p>The last step to have a compatible package is to create a<em> </em>file named <em>package.json</em> on the asset folder that suits the <a href="https://docs.unity3d.com/Manual/upm-manifestPkg.html">package.json template</a>, and you’re done. Here’s a sample below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*jNECJjXm9HdgPVK9lE5-oQ.jpeg" /><figcaption>package.json sample</figcaption></figure><p>You should have now a folder like the following one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*hd-t1I4dN4WPoUECiHLYhg.jpeg" /><figcaption>Bucket generator package folder</figcaption></figure><h3>Importing in UPM</h3><p>Once everything was settled, I tried to import the simplest package: the Asset Bundle Tool one (you’ll notice the outstanding description).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*dL5N8Vd0mgHgKL74gKZzEA.jpeg" /><figcaption>Asset Bundle package in the Unity Package Manager!</figcaption></figure><p><strong>Success!</strong> Oh, that was almost too easy, right?</p><p>Right.</p><blockquote>For packages without dependency, there is no issue at all after that. But most of my evolved packages have dependencies on the simpler ones, too bad.</blockquote><h3>Custom dependencies</h3><p>So I tried to add dependencies, using the same SCP pattern (ie package source like git@github:FredericRP/etc), but unfortunately, this pattern is not recognized.</p><p>After some research, I found out that custom packages <strong>can not have dependency at all</strong>. They say it’s a security reason so a package can not add a hidden package that would contain malware in it as npm can do. I understand that, but I still want to share my packages.</p><p>One solution is to make your own hosted scripts visible from the UPM, and that requires a properly configured scope package registry. For instance, my packages name starts with “<em>com.fredericrp</em>”, it&#39;s their scope, and I could use GitHub to publish packages as it can be used as a scope package registry.</p><h4>The solution for your own studio</h4><p>The UPM knows the Unity package registry, but no other registry. You can add one yourself by adding the following lines in the <strong>project manifest</strong> file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*l4puBEbwoveFM3w2ABmCoA.jpeg" /><figcaption>another package registry added in the project manifest</figcaption></figure><p>Here it is as text so you can copy/paste it:</p><blockquote>“scopedRegistries”: [<br> {<br> “name”: “FredericRP Standard Assets”,<br> “url”: “<a href="https://npm.pkg.github.com/@fredericrp">https://npm.pkg.github.com/@fredericrp</a>&quot;,<br> “scopes”: [ “com.fredericrp” ]<br> }<br> ]</blockquote><p>Once this step is done for a project, you can add any package from that repository with only their name!</p><p>I didn’t choose this solution as it requires too many steps for standard users, but I did test it to understand all the steps.</p><blockquote><strong>If you want to create your own studio registry and have your colleagues access it, I think this is the best solution!</strong></blockquote><p>You’ll have to:</p><ul><li>create an access token (github/ developer settings, with the <em>read:packages, repo, write:packages permissions)</em></li><li>log in using npm (if you don’t have one, create an account in <a href="http://npmjs.org/">npmjs.org</a>)</li><li>create a<em> “</em><a href="https://forum.unity.com/threads/npm-registry-authentication.836308/"><em>upmconfig.toml</em></a><em>”</em> file with valid credentials in it.</li></ul><p>If you want specific control on your packages or don’t want to use GitHub, you also can create your own package registry using <a href="https://www.npmjs.com/package/verdaccio">Verdaccio</a>, hosted on your own server. A more complete and sophisticated approach is <a href="https://openupm.com/docs">OpenUPM</a> that does a great job!</p><p>You can also add the following line in your package.json file to publish to your GitHub account (change the account name of course):</p><blockquote>“publishConfig”: { “registry”: “<a href="https://npm.pkg.github.com/@fredericrp">https://npm.pkg.github.com/@fredericrp</a>&quot; }</blockquote><p>Once all that is done, use the standard <em>npm publish</em> command line to upload and publish your package so it’s available for other developers (that have permissions on the repository).</p><h4>But… does it fit my needs?</h4><p>Ok, so that’s fine for a private package registry. But I want to share packages so everyone can access them easily, and that’s <strong>not easy</strong>!</p><p>Some developer has published a <a href="https://github.com/XRTK">core package</a> that adds a new scoped registry when the “core” package is imported, hosted on his server so it’s easy to import the other packages. I won’t do that, that’s my rule n°4. He also used NewtonSoftJson to read and write to/from the project manifest file and it also breaks my rule n°3.</p><p><em>To this point, I told myself that there were two solutions:</em></p><p><strong>a</strong>. use Unity Asset Store API to publish the packages on it directly.</p><p><strong>b</strong>. find a way to add dependencies from the repository somehow.</p><p>Unfortunately, there are no asset store API to publish packages, or I haven’t found them. I only know <a href="https://api.assetstore.unity3d.com/api-docs">APIs to get sales</a>. So I went for (<strong>b</strong>) instead!</p><blockquote>If you just want the answer and not the thinking process, skip next part :)</blockquote><h3>The Return of custom dependencies</h3><p>Instead of using the “<em>dependencies</em>” key on the package.json file, I added a “<em>custom-dependencies</em>” key in it:</p><p>Each dependency contains the full GiT URL with a version, for instance:</p><blockquote>git@github.com:FredericRP/Standard-Assets.git?path=/Singleton#1.0.0</blockquote><p>Once it’s done, I add a script called “DependencyUpdater” with the attribute <strong>[InitializeOnLoad]</strong> so I can execute a method right when the package is imported by Unity.</p><p>This script does the following:</p><ul><li>ask the UPM the current list of packages (no need to check the online status, it just did as we imported a package)</li><li>read the <em>package.json</em> file to check if there’s any custom dependency</li><li>add them in the project packages list</li></ul><p>I filter the package list to only check mine, so the package name starts with “<em>com.fredericrp</em>”.</p><p>The package.json file can be located under <strong>packageInfo.resolvedPath</strong> from that list (in fact, the AssetDatabase can also give you access to the package files, you have to use the package name with “/Packages/” prefix, without the version).</p><p>With a custom internal class, I can use <strong>JsonUtility</strong> to read this package file (that’s rule n°3). One issue though I encounter here is that a dictionary like the one used to list dependencies in a standard package file can not be read by Unity JsonUtility: it uses serialization and Dictionary are not part of the process (I could have used the System serialization instead but the next step will show that it did not matter). That’s why I made the “dependencies” value a list of strings containing both name and version.</p><p>Remember that we use the full GiT URL with the subfolder path, not the real asset name. After reading this, the script adds packages as the user did for the first one, using the <em>UnityEditor.PackageManager.Client.AddRequest</em> method. As simple as that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/1*h_aKjwN_rzCGghJWCBbMJg.jpeg" /><figcaption>Dependency updater prompts the user before adding packages</figcaption></figure><p>Using this “<strong>custom dependency updater</strong>” means that every single package (that has dependencies) has to contain this script, and it should destroy itself after usage so it does not conflict with the other packages when imported (or exist in the package namespace only, what a waste of space). Another way would be to publish this as an asset store free package and let it handle all packages import, but I’m not sure Unity would allow an asset that is a workaround for a security limit they created.</p><p>That was fun to create and taught me a little more about how packages are handled, so you can find it in its <a href="https://github.com/FredericRP/DependencyUpdater"><strong>own repository!</strong></a> But it’s still <strong>not the solution.</strong></p><p>Another dev coded a tool pretty close to this script (but fancier) as a GitHub package. The concept is similar, requires you to add this package so it can resolve other package dependencies and uses GitHub tags. You can find it on his <a href="https://github.com/k0dep/Originer">GitHub page</a> if you want to try it.</p><h3>Semi-automatic publishing</h3><p>That leaves me with the publishing API!</p><p>Wait, I said there was no API, did I?</p><p>When you are a publisher on Unity Asset Store, you have access to a portal that allows you to create packages, set their description, title, screenshots, see the download and sales data. They even added an API for this part (wow, first packages I shared were in February 2011, how old am I already ?)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*Q-fEEKHbCQYdmdEM-1z2fw.jpeg" /><figcaption>Downloads by month per asset on Unity Asset Store publisher portal</figcaption></figure><p>You have obviously a dedicated forum as a publisher for specific questions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*PvREKKFU01M8iAMcAyj9zg.jpeg" /><figcaption>asset store publishers unity forum</figcaption></figure><p>The creation process and the upgrade process require that you log in to the publisher portal.</p><p>From the portal, you have to create a new package or a draft for a new release of your package before anything else.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tMw1yGfELh-wN4vfpU4UXQ.jpeg" /><figcaption>Publisher portal: create a new package</figcaption></figure><p>After those steps, use the Asset Store Tools, available from the asset store, to validate your package and submit it.</p><p>Everything has to be made manually, using the website and editor windows. But if you look into the publisher website, you’ll notice JSON calls to the <em>kharma.unity3d.com</em> site, it looks like an API, right?</p><p>Other devs already looked into it, in fact, one of them shared a piece of code in the <a href="https://forum.unity.com/posts/5430324/">forum</a>. And another one included this with a little evolution in its RockTomato asset, as an <a href="https://github.com/RockTomate/Steps/blob/stable/Classes/AssetStorePublisher">AssetStorePublish step</a> (well, it seems they both looked into the same stuff in January).</p><h3>Final solution</h3><p>Before submitting the Standard Assets package to the unity asset store, I already had a test project used to check everything is ok and submitting the asset. But there’s no version control on this one as it’s essentially a project with a git submodules and the asset store tools imported and almost nothing more.</p><p>This is the main change: instead of only using this project to manually submit the project, I will use it to submit each one asset, using one script only, used when I tag a version on it.</p><p>Because I have no timeline telling there’s a big change in one asset, I still use one repository, but that will change too: one repository for one asset is the simplest use case, final point.</p><p>So let’s dig a little deeper into that process. Once again, if you just want the solution, skip this part.</p><h4>Login and fetch packages</h4><p>The API class created by the above-mentioned coders will change a little but the core is already here to be able to log in and fetch your packages as a publisher.</p><p>My goal is to:</p><ul><li>be able to select all the assets I want to update</li><li>save the configuration (aka: asset folder in the project, etc)</li><li>upload when I want it from an external script (ie: not launching unity each time I want to do it)</li></ul><p>Let’s start by creating an editor window that allows to log in and display the fetched packages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/347/1*cTYiEQFKqXh49s2GB8uFdg.jpeg" /><figcaption>Auto Submitter step 1: log in with password and display packages</figcaption></figure><p>Once you’ve logged in, Unity stores a session in its prefs, so you can use it without login twice for next API calls, so you can “auto-login”.</p><p>And I don’t want to have to log in, or auto-login, each time I want to change the configuration of one package, there should be a local cache or something, let’s do that! But of course, the update or upload can not be done if you’re not logged in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*ZvIewQ63QNmcYoiz_3qKKg.jpeg" /><figcaption>Display packages even when not logged in, but show a warning</figcaption></figure><p>Ok, once this is done, let’s test the upload!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*HrYThfTiFRB1lfAfm4Mkdw.jpeg" /><figcaption>package uploaded to the publisher portal</figcaption></figure><p>THAT IS WORKING!</p><p>From this same publisher portal, you can specify dependencies in the packages section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*wFLX0h_1bNKsVqfc9ib_pg.jpeg" /><figcaption>Unity Asset Store dependencies</figcaption></figure><p>As of today, it seems that dependencies are not available through the APIs, but it could change in the future.</p><blockquote>The publisher portal seems to link directly to old formatted asset store for now, and not V2 URL as required for dependencies in the same page, so be sure to browse your asset from the public asset store itself.</blockquote><p>Let’s continue the work. As I said, I want to be able to select the packages that will be uploaded from that project, and as a matter of fact, I’ve got a lot of deprecated packages and I don’t want to be distracted by them in the list, so I add a “visible” property to them. I also add a “status” indicator telling me if a package can be uploaded (for now, it’s green when the status is “draft” on the publisher portal, and black otherwise).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*f0bvvi7Ari6r8mAWQ9d9OQ.jpeg" /><figcaption>List, visibility, and status</figcaption></figure><p>Good, but not great. Let’s improve that window right away, using the internal icons! To use them, you just have to use the following code line, and the names can be retrieved using a little tool that I found <a href="https://github.com/GilpStudio/unity-internal-icon-browser">here</a>. It’s a great way to improve your editor window look and feel (if you don’t use Odin for instance). The second parameter starts with a pipe “|” so you only specify the tooltip for the icon.</p><blockquote>EditorGUIUtility.IconContent(“console.warnicon”, “|Status: “);</blockquote><p>In the process, I changed the window so you can select an asset to be uploaded only if the status is ok.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*SPVRGgy01jER7PBhlPtNwg.jpeg" /><figcaption>Better looking window</figcaption></figure><p>When an API is called, it’s a web request so it’s not synchronous: you can change configuration and save it but other calls should not be made if you don’t want any trouble. To prevent that and so the user knows what’s going on, I added a help box to indicate when a request is in progress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*AnenM36fupjWpq-NCGzP7Q.jpeg" /></figure><p>Final step: be able to use it without even launch Unity. Thankfully, with more arguments than before, you can launch it without GUI and call a method right from <a href="https://docs.unity3d.com/Manual/CommandLineArguments.html">command line arguments</a>.</p><p>For this step, I refactored a little my code so everything related to packages is located under the AssetStoreAPI class. The Editor Window uses the API and contains only the visuals and I create a new class, BatchSubmitterClient, that will be the class used with the command line.</p><p>For this to work, it has to be in an <strong>Editor folder</strong>, and the method has to be <strong>static</strong>. As we call APIs and the response is <strong>asynchronous</strong>, we can not use the “-quit” argument when we start Unity in batch mode otherwise it ends the process before the first call gets its response. But do not forget to end the process with <strong>Application.Quit()</strong> if you don’t want to lock your project and Unity to stay in memory. The command line is something like below, depending on your project path:</p><blockquote>Unity.exe -batchmode -projectPath “Drive:\Path\To\Project\Root” -executeMethod FredericRP.AssetStoreTools.BatchSubmitterClient.UploadPackages</blockquote><p>All cached data are stored in editor preferences, so it’s shared between all projects. That’s useful when uploading the same package with multiple unity releases to enhance compatibility checking and don’t see any trouble that could cause for now, but that may change.</p><p>That’s it for now!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*URdj_STUicwQZLmAUzIE3Q.jpeg" /><figcaption>Batch Submitter v1</figcaption></figure><p>Of course, the tool is <em>available freely</em> in its own <a href="https://github.com/FredericRP/BatchSubmitter">BatchSubmitter </a>repository, use the following URL to import it in the UPM!</p><blockquote>git@github.com:FredericRP/BatchSubmitter.git</blockquote><p>The next steps involve being able to change the configuration using command-line arguments, my time is split between day-job, kids and this side project, so I’ll update the tool asap but don’t have an ETA yet.</p><h3><strong>Other issues</strong></h3><p>During the upgrade of my GiT repo, I stumble into some issues that prevented me to be able to import the packages, but without any information on what the problem was.</p><h4>package no found</h4><p>Even if there’s a package.json file in the asset subfolder, having an invalid JSON file prevents unity to print the correct log in the console. That works when you import a package from a root folder in a GiT repo, but not from a subfolder. So if you have a package not found error printed in the console, check that your package JSON file is valid (I used a test repository with the asset put in the root folder to do so).</p><h4>unity hub still in memory</h4><p>When changing environment variables, you can close unity, reload it, and think that it takes into account the updated variable. You’re wrong: since it’s loaded from the unity hub and stays in memory by default, you also have to close it from its tray icon.</p><h3>8 new packages</h3><p>Those eight new packages are available from my GitHub page as before and will be soon published on the asset store as independent packages so you can now choose what you want to include in your project. I don’t have a roadmap yet for the other packages I want to include here, so be sure to watch the repo of my <a href="https://assetstore.unity.com/publishers/291">publisher page</a> for any update.</p><p>Thanks for reading!</p><p><a href="https://github.com/FredericRP/Standard-Assets">FredericRP Standard Assets GitHub page</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1339880dd09f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>