top of page
Dread Horse
  • Writer's pictureKhashayar Mohassesi

How to use Smart Code Wizard

Hi, in this post I'm going to explain to you how you can work with the asset Smart Code Wizard, it's really straight forward if you have experience working with 0.50+ versions of ECS from DOTS, because the inspiration for this asset was just that and applying those techniques for conventional unity development.


Installation

First things first, you have to do somethings to make sure the asset is working properly, when you extract the package in your project, there will be a SourceGenerator.dll file, click on it and make sure the settings in the inspector are like the screenshots below.




These might seem random, but that's how unity is setup currently (2021 LTS).

And one final thing is to set the api compatibility level to .NET Framework 4.x, since the assembly targets that, to do that go to do that, Go to Edit -> Project Settings -> Player -> Other Settings -> api compatibility level, and set it to .NET Framework (4.x), the one without the version number in 2021 LTS is the correct one! (weird decision by Unity but ok).

Now we're done, you can use the asset now, How you might ask? continue reading.

How you can utilize this asset

it's actually very simple, just whenever you write a script and you want the source generator to automatically resolve your getcomponent calls in a magical function, mark your fields with [GetComponent] and when you do that, the IDE will shout at you to use the partial keyword because there's another backing file connected to this class, and it will look like this:



well as you can see, there's no getcomponent calls and the class ends in what I've written, and somehow I'm calling InitializeComponents(), it's not something that's inside the monobehaviour class, the function was generated by the asset and just simplified a lot of "noise code" (the code that's basically doing the minimum to get things done).

Now you can ctrl+click the function to peek the generated code and it will be like this:

As you can see, it's not JUST writing the getcomponent calls, I went ahead and added safety measures to the code that it generates, so You and I can code safely and know what went wrong with our setup in unity. Interested in using this asset? Buy It On The Asset store from here!

3 views0 comments

Comments


bottom of page