Category Archives: Unity

Fixing Unity3D Hub on Fedora

Unity3D isn’t officially supported on Fedora, only RHEL & Centos. It will work fine, it just needs a little tweak.

You can install Unity Hub by following the instructions for RHEL/Centos here: https://docs.unity3d.com/hub/manual/InstallHub.html#install-hub-linux

After doing so, you’ll probably get a blank screen:

Unity Hub Blank

If you run Unity Hub from the console you’ll see the following error:

ERROR: Licensing SDK logging callback is not registered. Please use 'registerLoggingAdapter' function from the SDK to do
so.
If you try running the licensing SDK directly you'll get this error:
/opt/unityhub/UnityLicensingClient_V1/Unity.Licensing.Client
No usable version of libssl was found
[1]    694717 IOT instruction (core dumped)  /opt/unityhub/UnityLicensingClient_V1/Unity.Licensing.Client

You can see from the error that Unity is looking for an older version of SSL that is present on RHEL/Centos systems, but not newer version of Fedora.

To fix this, just install a compatibility version of SSL and kill any running versions of Unity Hub

sudo dnf -y install openssl1.1 && killall -9 unityhub-bin

Once that’s done, Unity Hub should work as expected!
If you’re still having trouble, a full reboot should do the trick.

Unity Gamepad with UI Touch Support

This is probably a really simple topic, but it had me stumped for a bit, so I thought I’d post about it.

I have a Unity game I’m developing that I’m adding controller support to using the Unity Input System. One of the things I realized was that, when Unity detected that a gamepad/controller was connected, the UI stopped responding to touch.

The really simple fix is that Touchscreen needs to be added as an optional component to the Gamepad input settings.

First, find your Controls prefab and double-click it.

Click the drop-down next to All Controls and choose whatever you called your gamepad settings (I called mine Controller).

Click the dropdown next to Controller (or whatever you named this control scheme) and click Edit Control Scheme.

Gamepad should already be set to required.

Click the + icon, choose Touchscreen, and set it to optional.

That’s it! Now whenever a player connects a gamepad/controller they will still be able to use the UI in touchscreen mode.

Fix for Android SDK Errors in Unity on Linux

When I add Android support for Unity on Linux as an additional module in Unity Hub, I find that Unity is unable to the SDK.

The problem appears to be that Unity does not set the binaries included as executable after extracting. I believe this may be fixed on newer versions of the Editor, but this is an issue for me on 2020.3.28f1.

The simple fix is to make all files in the AndroidPlayer executable. If Unity is open, close it.

Open Konsole or another terminal app.

cd ~/Unity/Hub/Editor/[Unity version]/Editor/Data/PlaybackEngines/AndroidPlayer
find . -type f -exec chmod +x {} \;

When you re-launch Unity, it should have no problem using the Android SDK.

VS Code Namespace Not Found With New Unity Input System

If you’re switching to the new Unity Input System and using Visual Studio code, you’ll probably hit the hiccup I did.

After switching back-ends, you’ll find that you’re not able to use the new namespace. If you try, you’ll get “namespace not found.”

using UnityEngine.InputSystem;

To fix this, you’ll simply need to create the csproj file so VS Code knows to use the new assembly.

In Unity Editor go to Edit->Preferences
Choose “External Tools”
Click the “Regenerate project files” button

After that, VS Code should recognize the new UnityEngine.InputSystem namespace!

Unity3d On Fedora

I recently switched from Ubuntu to Fedora and realized that Omnisharp in VS Code for Unity3D projects was not working correctly, even with Use Global Mono set to Always.

The fix ended up being simple: even though they are the same version, install Mono from the mono project’s repository, not Fedora’s.

First: Install mono from here:
https://www.mono-project.com/download/stable/#download-lin

Then, open VS Code and go to settings. To make this change for all projects, click User. To change for just this project (which I’d recommend) click Workspace. This will allow you to do your regular .Net development using the built-in mono (and eventually .Net Core).

Set Omnisharp: Use Global Mono to “always.”

That’s it! That should do the trick.

SSLStream Failure with .Net 4.x in Unity 2018.1

When Unity 2018.1 was released I jumped (perhaps too quickly) to using “.Net 4.x Equivalent” for the scripting runtime version under “Build Settings->Player Settings.”

Everything ran fine in the Unity Editor, but socket reads would silently fail after a few seconds on iOS.

I use SSLStream and SSLStream.Read() in a while loop running under its own thread. This runs without any issue using IL2CPP under the .Net 3.5 runtime, but fails almost immediately under iOS using 4.x.

I’m not sure what the exact problem is, but a forum post on unity.com seems to indicate that TLS related functions aren’t going to be fully ready using the .Net 4.x runtime and IL2CPP until 2018.2:
https://forum.unity.com/threads/questions-around-tls-support-on-2018-1.524917/

Either way, if you come across this issue, simply reverting back to .Net 3.5 seems to resolve the problem.

Create 1 Frame Animations in Unity 3D

I was looking to make a 1 frame animation in Unity and wasn’t able to find a guide. In case anyone is curious, this is what I did:

When making a multi-frame animation, you can simply select all of the frames in a sprite and drag them to the prefab. This creates the animation for you. However, if you drag just one frame from the sprite, it will add it as a sprite renderer.

If you would like  a 1 frame animation from that sprite, right click the frame you want in the Unity Editor and click Create->Animation

Ta da! You’ve now got a 1 frame animation.

New UI Prefab Scaling Solution

I recently changed the settings on my UI Canvas from “Screen Space – Overlay” to “Screen Space – Camera”. Which is how I’m sure it was supposed to be done in the first place (n00b here).

Anyway, in doing so, all of my UI prefabs were coming in scaled to 53.3333%.

I did a quick hack using a script to set those back to 1, but I figured there must be an elegant solution.

I finally found the (so, so simple) solution in the Unity forums.

When instantiating a prefab into the UI, you need to add the “false” argument when setting the parent.

Use

GameObject obj = (GameObject)Instantiate (prefab);
obj.transform.SetParent (parent.transform, false);

 

NOT

GameObject obj = (GameObject)Instantiate (prefab);
obj.transform.SetParent (parent.transform);

Deleting Child Objects Recursively in Unity

It took me a bit of Binging to find a method that worked the way I needed.

1st, create a public GameObject to hold the parent of the items you are looking to delete. Set this either from the Unity Editor or in code.

Then simply call a foreach loop on the parent GameObject as below to delete all children.

foreach (Transform child in searchResultParent.transform)
{
     Destroy(child.gameObject);
}

SSL at Last

It’s long over due, but I finally got an SSL certificate for shernet.com! Was happy to find (sorry for the advertisement) a Comodo Wildcard SSL cert on SSL2Buy for only $60. Was afraid it might be too good to be true, but everything went great, including testing a certificate reissue.

Unity engine will finally connect to my web server without yelling at me about an bad certificate. What a happy day 🙂