reference or Content.getComp....



  • Suppose I have a 200 sliders, 200 buttons 100 panels..etc..
    At several different places in the code, I need to get or set values from some of them
    What is best, is it to declare each one of the components or, in those places where I need the values, just get them with
    Content.getComp...?

    What is best practice? Why?



  • It kind of depends on exactly what you're doing.

    Generally it's best practice to get references to components up front in on init.

    If you need access them without a const reference then it's best to use Content.getAllComponents() instead of Content.getComponent(). getAllComponents has less overhead because it doesn't need to assign additional memory.



  • @d-healey so you're saying that there is no performance or memory difference? Except for the getAllComponents, which is more efficient, less memory demanding?
    I try to use getAllComponents as much as possible



  • @ulrik said in reference or Content.getComp....:

    so you're saying that there is no performance or memory difference

    I'm saying there is a difference between getComponent and getAllComponents when you are accessing component properties outside of on init.

    Without knowing exactly what you're wanting to do it's hard to advise the best approach but if it's outside on init and you don't want to create references inside on init you should use getAllComponents().



  • @d-healey thank you!


Log in to reply
 

9
Online

1.5k
Users

4.6k
Topics

42.1k
Posts