AI: Behaviour trees in Unity: Behave 1.1 released

updates: The error is gone after i install the Mono framework. And thanks a lot for this great plug-in :slight_smile:

I need some help with it. Every time i try to build library debug i got this error message in console.

System.SystemException: Error running gmcs: Cannot find the specified file
  at Mono.CSharp.CSharpCodeCompiler.CompileFromFileBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.CSharpCodeCompiler.CompileFromSourceBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] sources) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.CSharpCodeCompiler.CompileAssemblyFromSourceBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] sources) [0x00000] in <filename unknown>:0 
  at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromSource (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) [0x00000] in <filename unknown>:0 
  at Behave.Editor.Compilers.Unity.Compile () [0x00000] in <filename unknown>:0 
UnityEngine.Debug:LogError(Object)
Behave.Runtime.Resources:LogError(String)
Behave.Editor.Compilers.Unity:Compile()
Behave.Editor.Compiler:Run()
Behave.Editor.Compiler:smile:oCompile(IBehaveAsset, Boolean)
Behave.Editor.Compiler:Compile(IBehaveAsset, Boolean)
BehaveMenu:Compile(Boolean) (at Assets/Behave/Editor/BehaveMenu.cs:55)
BehaveMenu:Compile() (at Assets/Behave/Editor/BehaveMenu.cs:31)
BehaveAssetEditor:Update() (at Assets/Behave/Editor/BehaveAssetEditor.cs:34)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

The project is running with Unity3d 3.0 on Mac, and it’s a clean project with only the behave package imported. I’m a newbie programmer. Really don’t know what’s going on with this error. Please help me out.

That is really odd though. Is this the released version of Unity 3 or could it possibly be one of the pre-releases?

I also have an error when building my behaviour library in release mode:

It works fine in Debug mode though. And its pretty cool!

I do however also get an error if I run it on my iPhone: “EXC_BAD_ACCESS”. I get this only if I use Script Call Optimization of “Fast but no exceptions”. If I stick with “Safe and slow” it runs fine.

Any ideas?

Not sure about the iPhone optimisation problem. I will look into that. Regarding the compile error, could you post a screenshot of the tree responsible for that compile error?

Sure thing. Its just a simple setup to get my existing logic into a Behaviour Tree, then I can start doing what I want to improve the AI.

The image is below. If you need anything tested for the Script Optimization issue, just shout.

deleted

Just had a quick run through and it seems that release builds in general are broken. It is an easy fix and it will be out shortly. I intend to bundle it up with a few other changes though.

It is the final release of Unity 3.0 pro with iphone advance. I have installed it over my old Unity 2.6.1 version. I haven’t uninstall the older version first. So i’m not sure it’s the reason cause the problem. And since the new version only override the pro version. My unity iphone 1.7 still there. It might be the reason why i have to manually install the Mono framework? by the way, I could see MonoDevelop 2.4 under my Unity 3.0 folder.

I get the release compile error too.

→ Can run on all Unity target platforms.

I gather this also means Unity Pro + iPhone basic? or do you need iPhone advanced?

I’m playing with the old behave 1 editor demo to get my head around how it works, but I think you should fix the old demo to work with Behave 1.1 and release that as well - would make it much easier to demonstrate how it works.

ty!

Have it fully working now, and it is great. Converted my AI system to using a behavior tree in less than two hours.

Quick question though, let’s say you use a decorator as a lock for a task, if you have two trees running, and don’t want two tasks being run that affect the gameObjects position for example.

I can see how you would lock, just by incrementing a variable in the decorator, and then having decorators check to see if the variable is above a certain threshold, and if it is, return failure.

However, I don’t see how you could unlock, without putting code into the task(s) that would decrement the count, which kills the point of having a decorator.

Anyone know what the right way to do this would be?

Just finished uploading Behave 1.2. A few fixes in there including one for the broken release build. Also some additions: Priority selectors (thanks Jiong for pushing that up my TODO list again) and branch contexts.

More information here: http://angryant.com/general/behave/behave-1-2-released/

Quick question, is there a way to migrate trees over to the new version, or do they have to be redone from scratch?

I am having a little trouble making scripts work with Behave, do you have any updated examples? The ones I looked at were from before 1.0 and were not really helpful.

Hi
If I add a new decorator to the tree and change its name and try to build the library | get an error message saying:
“Comple error
Internal compiler error.”

If I don’t change the decorator name it does compile.

Any Idea why?

This looks great! Are you going to put together a demo for Behave 1.2?

Hi,

I just found out that the compile error I have only occur if I set a value for a floatParameter of a Decorator.
I’ll be glad for any help with that,Behave look’s like a great tool.

BTW: Is there any “official” place to post bug reports or discuss features of behave?

longshot wrote:

Just a guess:

I think you can perform locking on the Init call of the decorator, and unlocking on the Reset call. It’s look like the reset is called each time after the last Tick.

Can any one confirm this?

Hi. I am following the evolution of Behave and I have a question. Forgive me if it has been answered before but still, I haven’t made my feet wet with behave:

The goal would be to give to a character a basic behavior and as he evolves in the game to unlock and even create new behaviors for him. Also is there a possibility to save the characters current state of evolution and reuse in another level?

Thank you.

Trying desparately to get new Behave working in Unity3. Can anyone point out my error ( new to Behave coding). This is the Copper example

import UnityEngine
import BLCopperLibrary

class EnemyPoliceGuy (MonoBehaviour):
attackTurnTime = 0.7
rotateSpeed = 120.0
attackDistance = 17.0
extraRunTime = 2.0
damage = 1

attackSpeed = 5.0
attackRotateSpeed = 20.0

idleTime = 1.6

punchPosition = Vector3 (0.4, 0, 0.7)
punchRadius = 1.1

// sounds
public idleSound as AudioClip // played during “idle” state.
public attackSound as AudioClip // played during the seek and attack modes.

attackAngle = 10.0
lastPunchTime = 0.0

// Will be used to store a reference to the enemy behavior tree
enemyBehaviorTree as BLCopperLibrary.TreeType
currentTarget as GameObject

def Start():
Debug.Log(“On Start”)
characterController = GetComponent(CharacterController)

animation.wrapMode = WrapMode.Loop

animation.Play(“idle”)
animation[“threaten”].wrapMode = WrapMode.Once
animation[“turnjump”].wrapMode = WrapMode.Once
animation[“gothit”].wrapMode = WrapMode.Once
animation[“gothit”].layer = 1
audio.clip = idleSound

enemyBehaviorTree = BLCopperLibrary.InstantiateTree(BLCopperLibrary.TreeType.CopperBase_SimpleTree, Behave.Runtime.IAgent);
Debug.Log("enemyBehaviorTree " + enemyBehaviorTree)

def Update ():
pass

def FixedUpdate ():
if enemyBehaviorTree.Tick(self, null) != Behave.Runtime.BehaveResult.Running:
Debug.Log( “Resetting” );
enemyBehaviorTree.Reset( self, null );

def TickAction(action as int, sender as Tree, data as Object):
castAction = cast(BLCopperLibrary.ActionType, action)
Debug.Log("Action: " + castAction)
if castAction == BLCopperLibrary.ActionType.WaitForTarget:
LookForTarget()
if currentTarget != null:
return Behave.Runtime.BehaveResult.Success
elif castAction == BLCopperLibrary.ActionType.Attack:
Attack()
return Behave.Runtime.BehaveResult.Success
else:
Debug.LogError( "Unknown action ID: " + action );

return Behave.Runtime.BehaveResult.Failure;

// We can normally get away with not decaring the types, but it’s best to declare them to help Behave find the action
def ResetAction(action as int, sender as Tree, data as Object ):
pass

def TickDecorator(decorator, sender, data ):
return Behave.Runtime.BehaveResult.Success

def ResetDecorator(decorator, sender, data ):
pass

def PlayIdleSound():
// From the initial Idle method…
// if idling sound isn’t already set up, set it and start it playing.
if idleSound:
if audio.clip != idleSound:
audio.Stop()
audio.clip = idleSound
audio.loop = true
audio.Play() // play the idle sound.

// Don’t do anything when idle
// The perfect time for the player to attack us
yield WaitForSeconds(idleTime)

// Attempts to lock on a target
def LookForTarget():
PlayIdleSound()
currentTarget = null
// Verify if there’s anyone tagged “Target” nearby so we can attack it
// This will be done using simple proximity calculation for now
targets = GameObject.FindGameObjectsWithTag(“Enemy”)
for target in targets:
offset = transform.position - target.transform.position

// if player is in range again, stop lazyness
// Good Hunting!
if offset.magnitude < attackDistance:
Debug.Log("Will attack " + target.transform.GetInstanceID())
currentTarget = target
break
if currentTarget == null:
animation.Stop(“attackrun”)
animation.Play(“idle”)

def Attack():
animation.Stop(“idle”)
animation.Play(“attackrun”)

I use c#, but I think the API is the same in java script.

If you use behave 1.2 the signature of TickAction is different from what you used

you used def TickAction(action as int, sender as Tree, data as Object)
but the function signature in C# is

Tick(Behave.Runtime.Tree sender, bool init)

and to get the action id you use sender.ActiveID