How to populate prefab instances on scene with new variable?

mosowski 4 years ago updated by Lazlo Bonin (Lead Developer) 4 years ago 3

Let's say I have a scene / map with 100 instances of prefab with Flow Machine with some object variables. I need to add a new variable to this prefab with some default value set but I also need to adjust this new variable for few of the instances. When I add new variable and apply changes to prefab, not all instances are populated with new variable. Every instance that have one of previous variables changed from default will not receive update. Is it a bug or by design? How to deal with it properly in Bolt?

Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):

To null you mean? That's by design, but intended to include type hinting to keep it there in the future. What happens is a reference might have a type of it's assigned value, what happens when there is no value? It is just straight null, because there is no value to reference it's type from. A value, like bool, int, float, have default values, so they can stay.

How it essentially would be fixed is to have the type separated almost from the value field itself. So the value field is assigned based on the type field if it's null. Type as a reference, once set stay. So you could always refer to that.  

Hi, I'm talking about something different, specifically, but thing you mentioned is interesting anyway. 

I have a problem with object variables saved with object on scene. 

Let me explain it step by step:

1.  I have a prefab P with object variable x = 1 (primitive type, like int).

2. I create a scene with numerous instances of P. Let's say I have instance A of P and I change value of x to 2.

3. I need to add variable y to all instances of P, so I add it to the prefab with some default value and apply changes to this prefab

4. I expect that variable y would be visible in all instances of this prefab, but it turns out that it's only visible in only those instances of which value of x I haven't changed in the past. 

This means when I change anything in object variables list it is no longer considered as instance of list from prefab. It gets disconnected. I'd like to be able to make some use of prefabs even if I don't know all variables ahead of time.

When I add a new variable to C# script it is present in all objects that have this component, I'd expect Bolt to behave similarly.


Hi mosowski,

That's unfortunately a design limitation due to the fact that Bolt uses a custom serialization engine. This is necessary for you to be able to use any variable type (not just primitives, for example), but it messes with Unity's prefab change detection. As you noticed, as soon as one variable is changed, the prefab instance is marked as "dirty", and applying further changes on the definition will not overwrite it.

It would be very hard to circumvent that limitation. In fact, I don't think it's possible at all with the current serializer, FullSerializer. I know the Odin serializer has a prefab change tracking mechanism, but it is the only one that does as far as I know. Unless they eventually open their licenses to third party, this cannot be fixed.