Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Newbie afraid of spaghetti logic

Discussion in 'Visual Scripting' started by aaouviz, Apr 18, 2024.

  1. aaouviz

    aaouviz

    Joined:
    Apr 15, 2024
    Posts:
    16
    Hi all,

    I'm looking for a better way to do this with cinemachine.

    I have multiple cameras, I want to enable one via clicking on a box and disable all the others. The script attached works, but if I have 20+ cameras it will be quite ridiculous and I don't wanna be that guy.

    Any help much appreciated!

    upload_2024-4-18_10-58-22.png
     
  2. termway

    termway

    Joined:
    Jul 5, 2012
    Posts:
    94
    Hi there,

    I can think of two solutions for you:
    • Store all your cameras in a list, then disable all your cameras and activate the camera you want.
    • Store your current active camera in a variable and disable the previous.
    But I think you should create a subgraph that takes in a parameter, the camera you want to activate, and does all the necessary stuff inside that subgraph.

    Something like this:
    upload_2024-4-20_17-5-5.png

    upload_2024-4-20_17-5-10.png
     
    Last edited: Apr 20, 2024
  3. aaouviz

    aaouviz

    Joined:
    Apr 15, 2024
    Posts:
    16
    Thank you for your reply!

    I'm not familiar with Subgraphs, so I'll check these out.

    I actually figured this out, though, on my own :) ....I did basically exactly as you said with the variables, but set them as scene variables. It works well.

    Thanks again.
     
    termway likes this.
  4. termway

    termway

    Joined:
    Jul 5, 2012
    Posts:
    94
    Glad you figured this out yourself.

    Just a warning though, you should be careful when using multiple subgraphs in parallel (https://forum.unity.com/threads/incorrect-output-value-with-multiple-subgraph-instances.1302684/)

    My advice for you is that once you are comfortable with the Unity API (method names), you should drop visual scripting and learn C#. You will be so much better in the long run (functionalities, resources, version control, LLM, debugging, performance, ...)
     
    Gregoryl likes this.
  5. aaouviz

    aaouviz

    Joined:
    Apr 15, 2024
    Posts:
    16
    Thanks for the tips.

    I'm a huge fan of visual scripting - I was completely lost in Unity until I found it. I use node based systems in other work (grasshopper, tyflow, 3ds max material editor) so it works well for me.

    I don't plan on becoming a game developer or anything and I'm only using Unity to create simple interactive experiences for ArchViz so I do hope to stick to visual scripting, but if I make the move into more complex territory I do suspect you're right.