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. Dismiss Notice

probably simple but i got no clue: object forgets awake() set values on play

Discussion in 'Scripting' started by AVOlight, Jul 25, 2014.

  1. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    426
    Hello,

    what am I missing here? plz help me :)

    object forgets awake() set values on play

    copying the code from awake() to start() seems silly?
    do I call awake() in start? --> just tried that didn't work either..
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    ?...

    post the code?
     
  3. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    426
    Awesome asset! have you got anything planned for painting sprites?

    the codes quite a mess, i'm new to programming so i work through mostly by trial and error , which i know is silly but i'm to impatient for tutorials

    its a List<List<int>> thats throwing me a out of range when i edit a color after i hit play, and persists after i go back to editor mode
    after i remove and add the component back all is good until i hit play again
    when i'm in the editor i choose a color and it updates multiple pieces fine without the out of range
     
  4. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Already support it :). You can paint colors or images onto a texture.
     
  5. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    426
    cool!
    -----

    might be something do to with it being a List<List<int>>?

    Code (CSharp):
    1. [ExecuteInEditMode]
    2. [Serializable] public class colorManager
    3.  
    4. [SerializeField] public List<List<int>> colorLayers;
    5.  
    6. void Awake()
    7. if( colorLayers == null)
    8. {
    9. Debug.Log("List null again.......");
    10. colorLayers = new List<List<int>>();
    11. }
     
  6. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    426
    ............................ confirmed for some reason List<List<int>> nulls out after play mode..... i have no idea why this happens :(
     
  7. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    if that is all your code you are missing a step..

    1. [SerializeField] public List<List<int>> colorLayers;
    this doesn't create a list, it merely declares it "i am going to have something called colorLayers and it's public accessible and it's a listlistint...." being something other than a primitive its default is "null".

    You have to initialise the list by doing
    1. colorLayers = new List<List<int>>();
    i.e. what you've done, you just don't need to check if it's null since it is always going to be null at that stage.
     
  8. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    And why are you trying to serialize it? Don't count on that type being serializable in a million years.
     
  9. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    426
    Thank you for you help, yes the null happens on first wake setup --> and when i hit play mode which is after its been initialized --> it null again.

    I managed to work around this by ditching the list<list<int>> and using a list<myclass> (which has a list in it )
    so its something to do with serializing,,

    using a custom editor so...
    i don't understand why someone trying to customize the GUI should have to know what serializing is...

    any recommendations on visual scripting extensions? , can one edit the gui with them?

    btw can you animate the painting process with your extension?, cause that would be awesome
     
  10. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    I'm getting the feeling you're trying to do something in an "un-unity" way which is making things more tricky than you're expecting. Perhaps you could explain what you are trying to achieve with this approach, there might be a way of doing it in another way which is more straightforward?
     
  11. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    I think it's the fact that you are only creating an empty list that should contain lists of int.

    You need to loop through populating the List<int>.

    But if you are populating the List via the editor and relying on Unity to remember and populate the List<List<int>> then you should not be resetting the List on Awake().
     
  12. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    426
    I totally agree,, i think my color manager is going to make my brain explode the way it is now.. but it is working finally :) :eek:o_O :confused: :(...

    it just keeps track of objects in layers and then applies the same colors to the same layers,,, the objects are made up of parts and pieces so that got me a bit confused when building a collection to keep track of em

    -------

    it only sets it up if its null, yea i learnt this after my first couple out of range errors, List<List<int>> = new List<List<int>>(); List[x] = new List<int>();:cool:o_O:cool:

    smilies are fun