Some more textures made on a rainy day with mostly diffuse lighting from the sky.
Autor: dpgamingblog_tomtrottel_admin
Some free rather low-quality textures I made 1
Here are some free seamless textures I made with my crappy cell phone and GIMP.
I use them for study and concepts. I put them under Creative Commonds Share-A-Like, just dont sell them, despite of that do with them what you want. 😀
Custom Editor Struggles in Unity Stories, Beginner, Volume 1
I am doing a world system for Unity, mainly to seperate GameObjects from WorldObjects, but that is another story for another post.
So I have this structure which uses ConventionOverConfiguration and it works nicely.
But I did not want to do the same steps over and over, so I wrote a custom editor that just takes an active GameObject in the scene. Then it should add all the needed scripts, which itself where taken from other existing scripts or just the World Object / WorldGameObject base classes.
That is easy. But I ran into little troubles after I created these scripts.
I could not add them via script as components to the GameObject, which then I wanted to turn into a prefab.
So I write down the solution here, Stand Unity 2019.6.1.
Lets assume you used System.IO to create the new class for the GameObject. Then you want to add the class to the GameObject with inside the custom editor after the „Create World Object“ Button e.g.
sceneObjectToTurnIntoPrefab.AddComponent<"WorldObject sceneObjectToTurnIntoPrefab">();
You only have the name of the new class at this time as string.
Here is where the problems begin.
In this blog entry Unity3D said that AddComponent can not be used with a string anymore. You have to use the type or a generic class identifier. (You can do that with UnityObjects like GameObject or Renderer, though.)
Since the new class is not yet compiled, it is not availabe, so
sceneObjectToTurnIntoPrefab.AddComponent<Type.GetType(WorldObject sceneObjectToTurnIntoPrefab)>();
brings a error message, since this type does not exist in the assembly.
But you can not just give the new class name as string, even if the class would have been compiled. You need to also give the assembly full qualifier !
If you do not use an own namespace for your e.g. world system (which I did first), I just took a compiled class and got the full assembly qualifier so.
"WorldObject sceneObjectToTurnIntoPrefab, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
First, I did the error not to import the new script as asset. This I did then with
AssetDatabase.ImportAsset(MakePathRelative(pathAndNameOfFileToCreate), ImportAssetOptions.ForceUpdate);
AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
Now Unity3D knew about it, and started to compile it ! But, the compiling is asynchron ! So when I called
objectToConvertToAsset.AddComponent(Type.GetType(componentClassNameToAdd + ", Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"));
the class script that I wanted to add as component to the GameObject in the scene which I wanted to turn into a prefab was not availabe yet in the assembly.
I digged deep into the compiling process and the AssetManager, but in the end, after learning quite a few things, I found this Stackoverflow Post, which was exactly what I had been looking for and it works perfectly now.
I will write this down in detail later. (To be continued …)
Sunday Notices 06_09_19
So, I am flashing around with ProBuilder while doing some cute little robot enemies for Tank with Legs. Here two observations I did today with ProBuilder, which I really like to become a powerfull tool for quick prototyping and adjustments inside Unity itself.
- I made a quick subdivided plane and started to make a geographic easy terrain-like mesh out of it with PB. Then I wanted the mountain part to be seperated from the flat area. But doing so left some ghost verticies which I could not delete with ProBuilder afterwards. (Also exporting it into .obj and then importing into Blender did not help, since the exported object did not work in Blender 🙁 )

2. I wanted to use a triplanar shader for the mountains and found this two-year old shader on github : StandardTriplanar from keijiro.
While this shader works at least with default primitives, it does not work with meshes edited with ProBuilder sadly.

Level Generator
Once you write a structure down, it is most of the time not as complicated anymore. Actually. I am dissapointed how NOT complicated my structure of my Level Generator actaully is. 🙁 🙂

Of course there is a lot…well some more going on. The street map generator also calculates the spaces for the buildings available. But that is for another entry.
Unity, the Terrain and me, Part 2
After having the basics for this, see part 1, I created a plane and subdivided it a few times in Blender to have enough vertices in the mesh. I probably could use ProBuilder and do the subdivide there, but I try it first this way.

I imported the mesh as fbx into Unity3D and scaled it and moved it over the terrain. Now I want that every vertics of the mesh has the same y-axis height than the terrain at its x/z position.

Since I want to change vertices in the mesh, I have to set it to Read/Write Enabled in its importing settings on the model file.

First thing is to get the mesh data. But, and here I stucked last time I was trying this, the imported plane mesh asset only has a MeshFilter. What is a MeshFilter ?
„The Mesh Filter takes a mesh from your assets and passes it to the Mesh Renderer for rendering on the screen.“ (Unity3D – Documentation)
Since it is an instance, I am still not sure if I can change it at all. This is a basic flaw in my understanding of Unity3D. Please be patient with me here. 😀
But after reading the documentation, I noticed that last time I was trying this, I did it in editor mode. And there you are advised to use the sharedMesh field of the MeshFilter. And using that, you actually change the asset itself ! Unity3D clearly states, that you should not use sharedMesh for changing the mesh verticies.
If you use the mesh field of MeshFilter durching Run-Time, it creates a duplicate and every time you use mesh, this duplicate is returned. Also sharedMesh then points to this duplicate. So I will do that then. Here I only use one mesh, but for the planed used this is important, since there I will change a lot of instances of the same mesh.
And actually, this worked on the spot :
MeshFilter meshFilter;
Mesh mesh;
meshFilter = terrainCoveringMesh.GetComponent<MeshFilter>();
mesh = meshFilter.mesh;
Vector3[] verts = mesh.vertices;
Debug.Log("Found " + verts.Length + " Vertices for Tile " + terrainCoveringMesh.name);
for (int i = 0; i < verts.Length; i++)
{
Vector3 vertPos = terrainCoveringMesh.transform.TransformPoint(verts[i]);
Vector3 pos = vertPos;
pos.y = Terrain.activeTerrain.SampleHeight(vertPos);
vertPos.y = pos.y;
Vector3 backToLocal = terrainCoveringMesh.transform.InverseTransformPoint(vertPos);
verts[i] = backToLocal;
}
mesh.vertices = verts;
meshFilter.sharedMesh = mesh;
meshFilter.sharedMesh.RecalculateBounds();
meshFilter.sharedMesh.RecalculateNormals();

Important here is that you convert the vertices position from local space to world space and then back to localspace, using the transform of the mesh you want to lay over the terrain.
So this is done. Now how to get this working in Editor Mode is another question and the final problem.
Unity, the Terrain and me, Part 1
This is a very naive approach to the wonderfull world of Unity3D Terrain System.
I played around with it for a long time, did some cool things with it, like on-the-fly bomb craters via script and stuff.
It actually is time now to do this a bit more focused, since I am planing to use it in my game Tanks with Legs. For doing so, I started a laboratory session with Unity3D 2019.
First thing I want and need to do : Take a Mesh and put it on the terrain surface like a coat. I need this for my procedural level generator streetmap generator to make the streets or paths align to the height of the terrain.
But I ran into some problems while doing so and noticed I have to fresh up on a few things. I will do this very slowly and document it here.
Put a grid on the terrain
First thing I want to do is to put a grid of sphers on the terrain, on the same height as their world position on the terrain.
I setup a new GameObject and put a script on it which I named TerrainGridder.
First thing I need to know is which terrain to use, which is done by a public Terrain field so it can be assigned in the inspector.
Now I need to get the pivot world location of the terrain and then the dimensions of the terrain. Since the dimensions in the transform of a terrain is (1/1/1), this is not really usefull.
On a normal GameObject you would use the bounds of the Renderer Component, but since a terrain has no renderer (at least not by default or as component), you can use the size field of the terrainData field of the terrain. This field holds a vector with the dimensions of the terrain in worldScale.
With the method getHeight of the terrainData object of the terrain I can get easily the height of the terrain at a (x/z) world position.
So after using this code :
for (int y = 0; y < gridSize; y++)
{
float ypos = (terrainDimensionsInWorldScale.y / gridSize) * y;
for (int x = 0; x < gridSize; x++)
{
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
float xpos = (terrainDimensionsInWorldScale.x / gridSize) * x;
sphere.transform.position = new Vector3(xpos, terrainToGrid.terrainData.GetHeight((int)xpos, (int)ypos), ypos);
}
}
I have this grid on the terrain :

But if I change the height of the spheres using the retrieved y height with the terrainData method, it is nor working as excepted :

So what am I doing wrong here ? Let me investigate.
So first of all, it seems that I should use terrain.SampleHeight and not terrain.terrainData.GetHeight.
So with this code :
for (int y = 0; y < gridSize; y++)
{
float ypos = (terrainDimensionsInWorldScale.z / gridSize) * y;
for (int x = 0; x < gridSize; x++)
{
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
float xpos = (terrainDimensionsInWorldScale.x / gridSize) * x;
sphere.transform.position = new Vector3(xpos, terrainToGrid.SampleHeight(new Vector3(xpos,0,ypos)), ypos);
}
}
I get the result I wanted as first step.

The grid of spheres is now perfectly aligned on the y-axis according to the terrain height. With this I can start part two of the TerrainGridder : Taking a mesh and changing the height of its vertices to the height of the terrain.
Fast And Furious Image File Tagger (FAFIFT)
I needed a quick way to add tags to image files. A really quick way.
After searching for a program that fits my need, I was not able to find anything which would allow me to do this in a fast, simple and OS independant way.
In a flash of I NEED THAT I did it myself. After not so carefull planing I decided to give windows forms with C# a try, since I got quite used to Visual Studio thanks to Unity.
The result is the „Fast And Furious Image File Tagger“ (FAFIFT). It simply adds tags to the front of the file name and seperates them with two double underscores. Then you can use any search from any OS to find the images you tagged.

It saves the tags in a sqlite database and offers a autocompletion for tags you used before. It offers a tag editor and stores some statistics about the use of the tags.
The program still has some minor bugs, but I work with it daily and it really, really helps me to bring chaos into my pictures…eh ORDER. Also if I find something anoying or a minor bug, I update it quite fast.
I will not provide a compiled version yet, but the source is freely availabe on GitHub.
If anyone wants to make a good icon for it and donate it to the project, I would be happy ! 😀
Snap, the jobs a game !
First, I want to start with something simpler. And thats ProGrid, a unity package from the makers of ProGrid, available as preview package in the Unity Package manager.

You can set the grid size, easily toogle snapping on and off. Now lets have a look how compfortable this works.
I made a simple cube with a seamless texture on it. I activated snapping via the icon under the Eye Icon with the Grid next to it.

Then there is the „Lock the perspective grid center in place“ option, which I found very smart. You can either set the grid to be at the zero point of the scene, or it will be placed at the center of the current selected object.

After playing around with it, the most important thing is getting a feeling for using different gridsizes. One problem is that if the center of your object (in this case a default cube) is in the center of the object, you will have problems to position them at the borders of another project (or I didnt figured that out right now)
That was the result of 10 minutes playing around with ProGrid and ProBuilder. ProBuilder will be one of the next posts, I really start to like that tool, escpecially in combination with ProGrid.

In Unity we strive
I am writing my documentation for the level generation asset, cause, you know, humans forget things. Also I am doing the new animations for my Tank With Legs, which is quite difficult to be honest. At least to make them look awesome and make them work perfectly in Unity3D.
Also I need to dive into the NavMesh stuff of Unity3D way more to get the AI for my enviromentes created in the Level Generator the way I want them too.
To do this, I will make a training project in the Unity 2019.1 beta, using ProBuilder and also having a look at the preview packages, like ECS and the new physic modul.
I will write about it here, hopefully regularly.














