FindObjectsOfType – performance impact

FlowCanvas Forums Support FindObjectsOfType – performance impact

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #1669

    I’m using FlowCanvas in the “Graveyard Keeper” game. Our scene contains about 15,000 game objects.

    And when adding new objects it gives pretty significant performance spikes. The reason is using “FindObjectsOfType” which is pretty slow for a great amount of objects.

    I think that would be better to re-write such things as public static GlobalBlackboard Find(string name) to use some kind of a dictionary or a list to store all blackboards, to get rid of searching the whole world for them.


    Here’s another time consuming screen where stopping and starting about 30 of flowgraphs spends about 7 seconds!


    (Can’t make deep profiling at this scene because Unity crashes with out of memory)

    Developer at Lazy Bear Games

    You must be logged in to view attached files.


    Hmm. The GlobalBlackboard.Find method already uses a cached List and only fallbacks to FindObjectsOfType in very certain cases, like for example when the requested GlobalBlackboard name is not found, otherwise the cached reference is fetched from the list that is populated on Awake and OnDestroy of a GlobalBlackboard.

    Could it be that your flowscripts are asking for a Globalblackboard name that does not exists, or in other words, do you get any logs in the console like this: “Parameter ‘X’ failed to promote to a variable, because Blackboard named ‘Y’ could not be found” ?


    Join us on Discord:


    Yep. I’ve got this:

    <b>(NodeCanvas Warning)</b>: Started with null Blackboard. Using Local Blackboard instead.

    Maybe because I’m loading flow scripts and attaching them manually, through Resources.Load ?

    FlowScript res = Resources.Load<FlowScript>("FlowCanvas/" + name);

    Developer at Lazy Bear Games


    I’ve investigated further. The warning about the null blackboard was related to NodeCanvas. I’ve got rid of it and it is not related to the issue.

    I’m still having these performance spikes caused by FindObjectOfType.

    Further investigation and profiling got me this.

    For every 200 ms spike when creating a new object with a graph, I get:

    1. 100 ms spent for EditorApplication.RepaintHierarchyWindow() (which can be disabled in the preferences)
    2. 30 ms spent for instantianting a copy in GraphOwner.Awake
    3. 20 ms spent on outputing the log

    Developer at Lazy Bear Games


    Hello again,

    Hmm. Do you actually use any variables in the suspect graph, that are set to read from a GlobalBlackboard?
    The only occasion where I’ve found FindObjectOfType to be called from the GlobalBlackboard.Find method, is either:
    1) If the Graph requests a GlobalBlackboard before GlobalBlackboard.Awake had a chance to be called.
    2) If the GlobalBlackboard name requested is not found.

    Do you maybe load and attached flowscripts in Awake? If so, would you try doing so in Start instead?

    I will investigate the issue further, but would it be possible to get a reproduction case of how you load the graphs so that the FindObjectsOfType results in getting called?

    Please let me know.

    Join us on Discord:

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.