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

Question Using VS to set OTHER objects active/inactive - what am I missing?

Discussion in 'Visual Scripting' started by jdjddjdj, May 3, 2024.

  1. jdjddjdj

    jdjddjdj

    Joined:
    Apr 5, 2020
    Posts:
    10
    Hello!
    Am sure I am missing something really, really, really fundamental regarding using game objects in VS

    I am trying to set a third object active/inactive when my player passes thru a trigger object.
    The VS is on the trigger object itself which is just a simple cube

    Picture #1 works perfectly, deactivating the trigger object (self)
    Picture #2 does not de-activate the "roof dome" object (Grrr)

    Can someone point me to the "why" of why this doesnt work, or an appropriate workaround?

    Thanks very much
    JD


    WORKS
    1 - VS Set Deactivated - WORKS.png

    NO WORKY
    2 - VS Set Deactivated - NO WORKY.png
     
  2. termway

    termway

    Joined:
    Jul 5, 2012
    Posts:
    90
    In your second image, it looks like the GameObject you referenced is a .fbx.

    Prefab has full blue cube icon and normal game object reference has white cube icon like this.
    upload_2024-5-4_2-8-58.png

    But you can only reference game object if there are using embed graph (meaning drag & drop game object in the graph).

    upload_2024-5-4_2-10-23.png

    Another way would be to use one of the
    GameObject.Find
    or
    Transform.Find
    method to get your reference

    upload_2024-5-4_2-11-44.png

    Or to use a variable to store that game object reference.
     
    LaneFox likes this.
  3. jdjddjdj

    jdjddjdj

    Joined:
    Apr 5, 2020
    Posts:
    10
    THANK YOU @termway ! That got me thru the door.
    Had no idea about how the embedded VS affected things, or that "in the world of the VS Game object, not all objects are created the same."

    Have been progressing so fast on my project after this roadblock was cleared I forgot to come back here and thank you properly.

    For anyone reading this and having the same issue.... here how I got it all running

    My project is a space game... one aspect is the player flies thru triggers and various environmental objects appear/disappear based on the last trigger the player has flown thru.

    The player must have a Collider and a Rigid Body on it.
    I made simple cubes for the triggers with a box collider set to "Is Trigger" like this.
    I turned off the mesh renderer so the triggers are invisible in-game.
    Screenshot 2024-05-05 at 3.39.20 PM.png


    On each trigger object is a VS (set to embedded) that looks like this, with each trigger being assigned to activate it's particular universe and de-activate the unwanted ones when triggered :

    Screenshot 2024-05-05 at 3.39.08 PM.png

    Then, all of the objects I want to appear/disappear are parented under a new Empty object. (named UNIVERSE_1, UNIVERSE_2, etc etc)

    The last trick is to drag the name of each Universe's Parent from the hierarchy window into the "Set Active" objects in the VS, then set each "Set Active" node's boolean to yes or no as you likey....

    Voila! - kicks butt, and super duper easy to manage turning on and off large numbers of objects at will.


    Hope this helps other VS newbies like me.
    Am sure a more experienced coder has a (much) more elegant way to approach it.

    Thanks again very much Termway!! u rock.

    jd
     
    termway likes this.