Search Unity

Changing to Events, drains performance drastically - SOLVED wasnt eventsystem

Discussion in 'Scripting' started by zh4r0naX, Jan 18, 2020.

  1. zh4r0naX

    zh4r0naX

    Joined:
    Oct 30, 2016
    Posts:
    71
    Hi there,

    i just read about delegates and events and tried them out in my game. Iam creating a dungeon, once this is created my event gets fired and tells a few 100 object to perform one action ( adding themself to a list ).

    My FPS Dropped for the whole playtime now from an average of 60-70 in the editor to 24 - 32. So why is this happening ?

    My listening objects have this attached to their scripts.

    Code (CSharp):
    1.     public void Awake()
    2.     {
    3.         RunAfterDungeonCompleted.DungeonLayoutFinished += AddToGameManagerRoomList;
    4.     }
    And on disable the removal of this event.

    The event is created in the RunAfterDungeonCompleted script:

    Code (CSharp):
    1.   public delegate void StartOurGameGeneration();
    2.   public static event StartOurGameGeneration DungeonLayoutFinished;
    and is called once after the dungeonlayout is completed with:

    Code (CSharp):
    1.             if(DungeonLayoutFinished != null)
    2.             {
    3.                 DungeonLayoutFinished();
    4.             }
    Why is there such a massive performance drain ? Do i need to disable the listeners ? Where can i see how many active listeners are left ?

    EDIT
    It wasnt the event system. Thank you its solved!



    Thank you
    Justin
     
    Last edited: Jan 18, 2020