Search Unity

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

Discussion in 'Prefabs' started by Deleted User, Jul 23, 2019.

  1. Deleted User

    Deleted User

    Guest

    Using 2019.1.11f1 but this happened in previous versions.

    I have a game object that has a script.
    1. the prefab created after filling the properties of this script does not store the values,
    2. overriding so that these values are stored in the prefab does not work either.
    Sans-titre-1.jpg Sans-titre-2.jpg
     
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    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.
     
  3. Deleted User

    Deleted User

    Guest

    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.
     
  4. Deleted User

    Deleted User

    Guest

    All right, I've pinned something.
    1. if the script added to the game object has properties that point to prefabs in the Project view, overrides works.
    2. 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.

    Capture.JPG
     
  5. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    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.
     
    ow3n likes this.
  6. Deleted User

    Deleted User

    Guest

    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.
     
  7. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,332
    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?
     
  8. Deleted User

    Deleted User

    Guest

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

    immersia_dataviz

    Joined:
    Mar 8, 2019
    Posts:
    8
    I right-clicked the prefab, reimport, and magically started working