Prefab doesn't save script properties values, override doesn't work either

Using 2019.1.11f1 but this happened in previous versions.

I have a game object that has a script.

  • the prefab created after filling the properties of this script does not store the values,
  • overriding so that these values are stored in the prefab does not work either.

4774751--455039--Sans-titre-1.jpg

Are the referenced objects on GameObjects in the scene that are not part of the same Prefab? if so, they can’t be saved into the Prefab Asset and it’s expected that they stay as overrides.

Uh… no they are plain and simple prefabs, like it shows on the image I posted. Just a game object with a script added.

I’ve noticed something though; I’m going to test it and I’ll post the result here.

All right, I’ve pinned something.

  • if the script added to the game object has properties that point to prefabs in the Project view, overrides works.
  • if the script added to the game object has properties that point to objects that are in the hierarchy view, overrides does not work.

Image of the game object prefab after overriding; you can see that part of the properties have been saved, these are prefabs, the two missing objects are in the hierarchy view and I cannot use the game object prefab in this case.

4776941--455423--Capture.JPG

Yes, that’s what I was trying to say.

Referenced GameObjects in the scene (e.g. in the Hierarchy) that are not part of the same Prefab (not a child of the Prefab you’re trying to apply to) can’t be saved into the Prefab Asset and it’s expected that they stay as overrides.

Prefabs are meant to be able to be used in different scenes, so they can’t contain references to objects that exist in a specific scene.

1 Like

It’s too hot for me to think clearly right now but has it always been like that? I don’t remember prefabs behaving that way in previous versions.

You could never have a reference from a prefab asset to an object in a scene. Instances of the prefab in the scene could of course have references to other objects in the scene, but those wouldn’t be stored in the prefab.

That makes perfect sense - what would you expect to happen if you instantiated that prefab in a different scene?

What would be a new bug is if you create an prefab from an object in a scene, and the object in the scene (now an instance) lost all the references it used to have to other objects in the scene. But I don’t think that’s what you’re saying here?

You’re right; it’s the prefab made from the object on the scene that loses all references to other objects on the scene.

I right-clicked the prefab, reimport, and magically started working