Problems arising from multiple animations and how I dealt with them

First off, no idea if this could help anybody, but I definitely wanted to write it down as solving my issues was quite a ride. Been deviating more than before starting with this tutorial.

general info:
For the animations I originally had 3 different animations with 3 different controllers for coming from the top, left or right depending on the position’s x value. Depending on x I’d assign the correct controller at runtime while the spawner used to store all my controllers in an array to load said controller from.
(I’m following all tutorials on Unity 5 btw)

Anyway, in order now:

First time I noticed something was wrong ->
I couldn’t build to WebGL, in fact, I couldn’t build anything at all.

All I got was a standard Windows error sound and a super unhelpful “there’s something wrong with your scripts” type message when I clicked on the build button. VS didn’t show me any errors in those scripts though (spoilers, indeed there weren’t any from it’s perspective).

Through googling I then found out about the Editor Log. Looking through there I finally got some directions on where these script errors originated.

new problem -> my scripts used to directly work with UnityEditor.Animation classes

As I’ve found out through more googling, anything that uses “using UnityEditor” (which I needed to store the animation controllers) is only working in the editor preview but won’t be able to be built unless the scripts are placed inside the special folder named “Editor”. So I tried that…

next up -> the scripts I just put in the new folder were suddenly unknown to the rest of my scripts. Turns out “Editor” folders are compiled last or something like that so all my normal scripts had no chance of knowing of their existence and were now throwing errors instead.

hacked solution -> instead of storing the controllers in my enemySpawner I used another special folder, the “Resources” folder. With that I could set the correct controller at runtime just as planned and all worked fine. Only thing bothering me now was that whenever you ask the internet “When do you use the resources folder?” the answer is: “You don’t.”

But I just had gotten another idea and realized how stupid I was for not seeing this ealier.

final solution for me -> delete the animation controllers, 1 is enough

Instead of having 3 seperate controllers for the 3 animations, I just put them all into 1 controller and played them depending on an int-parameter defined there. Now an enemy checks on Awake where it’s x position is -> sets the animator controller’s value then accordingly and in turn plays the correct entry animation.

Was quite an unexpected hassle, at least it’s working now :3

thanks for sharing you experiences with us, maybe is a good ideia a moderator move this to another section.

It is to do with Unity and Laser Defender though?

It is, but this forum is for sharing your games right ?

The forum, not solely, no.

Or do you mean that the original poster’s post doesn’t fit with the lecture content from the course for which this category is meant for?

I just mean this section of the forum is to showcase your work, or I am wrong?

1 Like

The specific lecture is for updating Laser Defender to Unity 5 and subsequently creating a WebGL build.

I would suggest that if there are questions relating to that lecture, or notes, suggestions, issues and how they were overcome then they would all belong in this sub-category also.

There is a specific Showcase sub-category which can be used for show casing any Unity projects, whether they are from the course, or, student’s own versions of the games. Equally, it doesn’t really hurt if a game is showcased in the appropriate lecture’s sub-category.

The original post does suggest the WebGL build but also has a few other items mentioned to, more of a general how I accomplished it type of post, as WebGL is only mentioned in this specific lecture I think it would be ok to leave it here for now.

Privacy & Terms