Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Feedback Which of the 2 methods is more efficient?

Discussion in 'Input System' started by SaresITA, Oct 30, 2021.

  1. SaresITA

    SaresITA

    Joined:
    Feb 19, 2020
    Posts:
    28
    Which of the 2 methods is more efficient?

    Hi, I'm creating a text adventure for educational purposes. I am divided on how to make the player change Room. Both methods work, but I would like to know which of the 2 weighs more on the ram
    (yes I know, the difference is minimal, but this allows me to understand if it costs the ram more to read code or read different events)

    With the first method, we call any action with a single event.
    With the second method, we need to create 4 different events, which return a string.

    CODE:
    https://pastebin.com/kGFkDtdB

    IMG:
     
  2. dmytro_at_unity

    dmytro_at_unity

    Unity Technologies

    Joined:
    Feb 12, 2021
    Posts:
    212
    Tbh, performance implication is minimal on this scale (e.g. you're not calling this thousands of times per frame, maybe just once in a few dozen seconds). Chose whatever is easier for you to work with.
     
  3. INeatFreak

    INeatFreak

    Joined:
    Sep 12, 2018
    Posts:
    46
    I think method1 should be a bit faster. Though you better cache that ReadValue if you gonna use it multiple times.

    var vec2 = value.ReadValue<Vector2>();
    if(vec2.x > 0) {
    // ...
    } else if(vec2.x < 0) {
    // ...
    }