Achievements in Brain Builder¶
Opened Brain Builder¶
There are two ways to open the Brain Builder. The easiest way is to, when you have added a Brain to a game object, is to click on the “Edit…” button in the inspector for that object:
The other way is through the “Brain Builder” option in the “Window” menu:
Used Beginners Blocks¶
The A Beginner’s Guide are a set of friendly blocks that help you get started with Brain Builder. The guide is found at the top of the left panel, and hovering the title gives an introduction on how to use them:
Moved the object forward¶
The rule created above will move the object forward.
Snapped a block on top of another¶
If we want to use the arrow keys to move the object forward, find the “UpArrow” and “Key is down” blocks in the beginner’s guide:
Move the “UpArrow” block on top of “Key”. “Key” will light up when you can drop something on top of it.
The result should look like this:
Alt-dragged a numeric value¶
If you hover your mouse pointer over a numeric variable, such as the arguments to the following method:
You can hold down the Alt key and drag that variable to sets its value. The result should be something like:
Formed an implication¶
If you want an action to be executed conditionally – let’s say if a user presses a certain keyboard button – you will need an implication. An implication is formed by placing two groups of blocks next to each other horizontally:
If the user presses the up arrow key, then we should move forward.
Formed a conjunction¶
If you want multiple conditions to hold before executing an action, you can stack blocks on top of each other to create a conjunction:
Of course, if you want multiple actions to execute, you can stack them on top of each other as well.
Used the search field¶
The grey box above the list of blocks is a search field, which lets you quickly find stuff if you know the whole or part of the name. Or you could just type something that sounds reasonable and read the documentation for what you find!
Opened the manual for an achievement¶
As you probably found out by now; clicking on an achievement takes you to this helpful documentation. Congratulations!
Renamed a variable¶
By double-clicking on a variable, you can rename it to something that better suits your needs. If you have multiple variables with the same name in a rule, all of them will be renamed:
After double-clicking, typing the word “newCube” and pressing enter:
Created a string out of a variable¶
The double-click to rename variables does not end there! If you want a string constant from a variable, just type a quotation mark (”) and start typing your string:
After double-clicking, typing a quotation mark and the words “Hello, world!” and pressing enter:
Panned canvas¶
If you alt-drag on the background, you will move all rules around. The scrollbars in the bottom and to the right will help you to not get lost.
Dropped a game object from the scene¶
If you want a reference to a game object from the scene, or a part of a prefab’s children, simply drag it from the project or the scene hierarchy into the canvas. Dropping it directly on the canvas will create a Game Object block:
Dropped an object from the scene onto a block¶
If you want a specific component of another object in the scene, you can drop it directly on a variable of that type. For example, to change the color of a light when a key is pressed:
Created a slot of primitive type¶
By dragging game objects to the Brain Builder window, you are actually creating “Slots” - values which the brain can use and you as the designer can edit in the inspector for the Brain component.
You can also create your own slots without dragging objects into the workspace. Click the “Create” button in the top left of the Brain Builder window and select “Slot”. The slot will appear in the inspector as well.
If you need a value that can easily be modified from the editor, or just a common value across the whole brain - such as the maximum movement speed of a character - you can use a slot of a primitive type. Right-click the new slot in the left panel and choose “Edit”.
To change the type, select a new type from the drop down. Click outside the box to close it. For example, choose color and rename the slot to “Light Color”:
Now look at the inspector. There will be a color picker which you can set a new color from. You can even change it at runtime (but bear in mind that it will be reset by Unity when you stop the game).
Created a custom block¶
A custom block is an abstraction for a set of actions or sensors. For example, if you want to use the same couple of actions in multiple places (varying on some parameter), you could use a custom block to avoid repetition.
To create a custom block, click on the “Create” toolbar button to the left, and select “Block”.
Defined a custom block¶
To define a value block, place it to the left or to the right of any set of actions, for example:
If the block only appears at the left hand side of blocks, it will be considered an action, and thus become red. If it only appears on the right hand side of blocks, it will be considered a sensor, and thus become blue. As we will see in the next section, if it both appears on the left and right hand side of blocks, it will become green.
Created a custom value¶
Like custom blocks, custom values are intended to reduce repetition of common tasks. Unlike custom blocks however, custom values represent values instead of actions or sensors. If you got some complex expression that you use in many places, you can create a custom value to replace it.
Custom values are created the same way custom blocks are.
Defined a custom value¶
To define a custom value, you drop it in a “object1 is object2” block and place it by itself. It will then turn yellow. Now, when you use your custom value, it will get replaced by what you defined it to:
Used a custom value¶
A custom value can be used just as any other block that represents a value. Drop it wherever you like!
Used an event in a rule¶
Events are special blocks that trigger when certain things happen inside Unity. For example, when your object enters another collider, the OnCollisionEnter event will trigger. Use it like the following:
This will write the name of the colliding game object to the console.
Created a Raycast¶
Raycasts can be immensely useful in a 3D environment. If you want to see if a character can see another character or if a character can walk in a certain direction, raycasts can help you.
A raycast works as a sensor:
This will send a ray from my position forward 5 units. The hitInfo parameter will be populated with the collision data if it succeeds.
Precompiled brains¶
To speed up initial compilation of the brains, as well as making your project iOS-compatible, you will need to precompile your brains before you run/build your game. To precompile all brains in the project (from all scenes in the build settings), press the “Precompile Brains” button in the top right of the Brain Builder window.
This will place a “PrecompiledBrains.dll” in the “BrainBuilder/Plugins” folder. If you edit your brains after you have precompiled it, you will get a warning, and the precompiled brains will be ignored. To remove that warning, simply remove the “PrecompiledBrains.dll” file.