Using Behavior Tree in prefab only works if you don't change a thing?

Justin

Administrator
Staff member
I haven't got the editor open in that case, so that was the difference. I'm glad you've fixed it.
I'll send you a PM with the fix to be sure.


I understand that I could set the variables at runtime but if I have an AI with defaults, I want to configure the variables based on the position where I put the AI in. Also, for example, the waypoints are needed to be set for every AI.
In that case instead of updating the variable values on the Behavior tree component you would update them on your own component that sets the value at runtime. This way you can configure the variables based on the position and still use the prefab system without any conflicts.

but I don't force this solution because I haven't tried it.
The problem with that solution is that the override variable is still serialized within the JSONSerialization field so it will be overridden by the prefab instance. The true solution is to have the fields separated out when Unity serializes so it can recognize each variable value within the prefab system.
 

SXtheOne

New member
Sorry for the late reply, currently I'm involved in 3 projects and only one is using BD.
I've tried the latest fix and tested the issues presented in the numbered videos. I'm using Unity 2021.3.3f1. Here are the results:
#1 and #2 are not fixed
#3 seems to be fixed, now the correct value is set when I start the game
#4 is not fixed, correct values pop into the prefab instance when I start the game
#5 seems to be fixed, deleting a variable from the external tree deletes it from the prefab as well
 

SXtheOne

New member
Hi, here are the new results:
#1 and #2 are fixed
#3 is partly fixed now. The new field appears, and if the prefab instance is not changed, its value is there BUT if the prefab instance has a changed value, the value is missing even after starting the game.
#4 is fixed
#5 is fixed

As you can see we are progressing. :) Unfortunately, I found a new one that is serious:
#6 - deleting a value from prefab makes the changed prefab instance's identical type values switched (the ext. tree has two, identical type values under each other).
 

Justin

Administrator
Staff member
Glad we are making progress :)

Unfortunately that looks like it's hitting the limits of the prefab system with a single field. The wrong value appears because you changed the prefab instance values before deleting the transform value. You'll notice that the Unity Object reference index didn't change on the instance and this is because the prefab system marked that field as changed.

If you use the method that I described in this post with using another component to set the prefab values and using Unity's serialization you'll be able to work around this issue without an major workflow changes.
 

SXtheOne

New member
As I mentioned earlier I have a workaround that automatically generates a class for the external tree with the variables so I've already used a method like that but it's far from ideal.
Is there a plan/timeframe when the Behavior Designer serialization method gets changed for something else from this one field JSON solution (like saving an array that Unity can serialize easily)? I think every new member would welcome that and probably everyone who uses this product to make commercial games.
 

Justin

Administrator
Staff member
It is a pretty major change and there are still some limitations with SerializedReference (see this thread). With that said, I definitely want to test it out for the next major update. We are working on the character controller update and then my focus is on Behavior Designer.
 
Top