Graph.OnEnable() cost too much CPU time ! How to optimize this problem?

FlowCanvas Forums Support Graph.OnEnable() cost too much CPU time ! How to optimize this problem?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #3315
    fatiao
    Participant

    this profile picture is attached!

    Attachments:
    You must be logged in to view attached files.
    #3317
    Gavalakis
    Keymaster

    Hello there,

    It all depends on what you are doing on the Graph OnEnable node output. The node itself does not have any performance impact, but what you have connected on its output can have. Can you please post a screenshot of your graph nodes connected to your OnEnable node output?

    Thank you.

    Join us on Discord: https://discord.gg/97q2Rjh

    #3325
    fatiao
    Participant

    Each gameObject is initialized, it will call StartGraph function, this function will access each flowcanvas node, if the number of node is large, then consume too much main CPU time!

    The CPU time cost here!
    —————————————-
    ///<summary>Start the graph for the agent and blackboard provided with specified update mode. Optionally provide a callback for when the graph stops/ends</summary>
    public void StartGraph(Component newAgent, IBlackboard newParentBlackboard, UpdateMode newUpdateMode, System.Action<bool> callback = null) {

    #if UNITY_EDITOR
    Debug.Assert(Application.isPlaying, “StartGraph should have been called in play mode only.”);
    Debug.Assert(!UnityEditor.EditorUtility.IsPersistent(this), “You have tried to start a graph which is an asset, not an instance! You should Instantiate the graph first.”);
    #endif

    Debug.Assert(newParentBlackboard != this.blackboard, “StartGraph called with blackboard parameter being the same as the graph blackboard”);

    if ( newAgent == null && requiresAgent ) {
    Logger.LogError(“You’ve tried to start a graph with null Agent.”, LogTag.GRAPH, this);
    return;
    }

    if ( primeNode == null && requiresPrimeNode ) {
    Logger.LogError(“You’ve tried to start graph without a ‘Start’ node.”, LogTag.GRAPH, this);
    return;
    }

    if ( isRunning && !isPaused ) {
    Logger.LogWarning(“Graph is already Active and not Paused.”, LogTag.GRAPH, this);
    return;
    }

    if ( !hasInitialized ) {
    Initialize(newAgent, newParentBlackboard, false);
    } else {
    //if the graph has pre-initialized with same targets, this call does basically nothing,
    //but we still need to call it in case the graph is started with different targets.
    UpdateReferences(newAgent, newParentBlackboard);
    }

    if ( callback != null ) { onFinish = callback; }

    if ( isRunning && isPaused ) {
    Resume();
    return;
    }

    if ( _runningGraphs == null ) { _runningGraphs = new List<Graph>(); }
    _runningGraphs.Add(this);
    elapsedTime = 0;

    isRunning = true;
    isPaused = false;

    OnGraphStarted();

    for ( var i = 0; i < allNodes.Count; i++ ) {
    allNodes.OnGraphStarted();
    }

    for ( var i = 0; i < allNodes.Count; i++ ) {
    allNodes.OnPostGraphStarted();
    }

    updateMode = newUpdateMode;
    if ( updateMode != UpdateMode.Manual ) {
    MonoManager.current.AddUpdateCall((MonoManager.UpdateMode)updateMode, UpdateGraph);
    }
    }

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