Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Prefabs public properties are reset on play, after accessing game.db from editor

Discussion in 'Scripting' started by donov, Dec 8, 2015.

  1. donov

    donov

    Joined:
    Apr 15, 2013
    Posts:
    55
    Hi everyone

    I got a weird problem

    We got this editor scripts that deals with creating prefabs for level segments, they got a structure and a script with public values that sits on top of the hierarchy and holds some references to transforms down in the hierarchy etc. this all happens in the editor.

    weird thing is, sometimes when I do a DB access from the editor script, to say save a level configuration, what segment prefabs it is built from etc. so not even touching segment prefabs.
    When I play my game, a bunch or all of my segment prefabs in the resources folder have lost all references, and I see them all changed in SourceTree

    any help is much apretiated
     
  2. 3zzerland

    3zzerland

    Joined:
    Oct 31, 2014
    Posts:
    42
    Your question isn't 100% clear.

    Since you mention SourceTree, I'm assuming you are using git for Version Control and by game.db, I am assuming you are talking about pushing/pulling data from your git db using sourcetree.

    Are you storing the entire project folder in git, or just the assets? Your script references are stored in a file outside of the assets folder so you can lose references when multiple people are passing data without being cautious on pushing these files.

    Additionally, Perforce is free and has a (still work in progress) free Unity integrated tool called P4Connect on the asset store. I'd recommend checking into this for version control as it's quite powerful, though very different from git.

    I apologize if I've misunderstood your troubles.

    Regards,
    Rob
     
  3. donov

    donov

    Joined:
    Apr 15, 2013
    Posts:
    55
    Yes git for version control, but by accessing game.db I mean an SQLLite DB that we use in the project, has a table SegmentConfig(Segment prefab path in Resources folder, type etc..) and LevelConfig, data in tables is json serialized, etc..

    My segment prefabs sit in a resources folder and are basically a hierarchy structure that has a game object with a monobehaviour on it that holds public references from its children transforms.

    my issue is when accessing the DB from an EditorWindow script to add a new row in a table for ex, when I press Play, Segment prefabs get changed and loose all references in that monobehaviour script

    I can clearly see it in source tree, FileId: 41234512342314 becomes FileId:0 for all prefabs for ex..

    I thought its a serialization problem, but the properties are public, and mostly Transforms that are child of the current GO

    Entire project is on git
     
  4. 3zzerland

    3zzerland

    Joined:
    Oct 31, 2014
    Posts:
    42
    Okay, slightly different than the problem I was envisioning.

    So:
    You add a new row to your table via editor window, then hit play and have lost references?
     
  5. donov

    donov

    Joined:
    Apr 15, 2013
    Posts:
    55
    yup, and just narrowed it down when it happens.
    if I do any asset change via editor script (prefab, db...) and a reimport of changed assets does not happen, all hell breaks loose on Play. to make matters worse there is a Unity bug in 5.1.2p3 where you need to switch focus from Unity so importing update happens.
    I fixed my problem by calling AssetDatabase.Refresh() after each asset change and so far no broken prefabs. thank god, this was driving me nuts for weeks.

    I guess if Unity does not reimport the changed assets before pressing Play, something gets broken with serialization and references are lost

    thanks anyway
     
    3zzerland likes this.