How to console print everytime something is added to a list
I'm writing some automation in the editor and would like to have it automatically Debug.Log the items that are getting added to a list. I could go line by line and do this prior to my array but that would be tedious as it's thousands of lines. Here is what I have thought up:
 List<string> _convertLog = new List<string>();
 List<string> convertLog
         {
             get
             {
                 return _convertLog;
             }
             set
             {
                 _convertLog = value;
                 Debug.Log(value);
             }
         }
However its also getting used like this:
 CB_COMP_vThirdPersonController(_copiedPlayer, ref convertLog);
That's throwing errors on me:
A property or indexer may not be passed as an out or ref parameter
What's the best way to do this?
Answer by CodesCove · Jun 24, 2020 at 10:18 PM
One way (not necessarily the best) to do this is to make your own list by deriving from normal list and make a new Add method.
            class _List<T> : List<T>
             {
                 public new void Add(T item)
                 {
                     base.Add(item);
                     Debug.Log(item.ToString());
                 }
             }
Then you can define your list
         _List<string> mylist = new _List<string>();
When you use mylist.Add("your string") it will also debug.log it to the console
Your answer
 
 
             Follow this Question
Related Questions
How to Undo a bool on an EditorWindow 1 Answer
Read JSON file data from server to unity c# 0 Answers
How to reduce editor refresh time? 0 Answers
How do I fix the Editor GUI in the latest update,Why does the editor no longer render 1 Answer
Handles.DrawAAConvexPolygon, but for any kind of polygon, not just convex. 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                