Search Unity

Finding an GameObject with mainCamera

Discussion in 'Visual Scripting' started by defied, Sep 4, 2022.

  1. defied

    defied

    Joined:
    Dec 4, 2020
    Posts:
    17
    Hey all!
    I decided to try out visual scripting and I was wondering (I googled the heck out of this and didn't find anything) what nodes one would use to return the information of an object at the center view of the camera.

    I tried raycast hits, and the best I could pull was vector information.

    Any help would be appreciated. I've been fighting it for a couple of hours now.

    Thanks!
    D
     
  2. defied

    defied

    Joined:
    Dec 4, 2020
    Posts:
    17
    I *might* have made some progress.

    upload_2022-9-3_19-59-45.png
     
  3. defied

    defied

    Joined:
    Dec 4, 2020
    Posts:
    17
    Okay, so it looks to be working, however it seems it's not focused on the center target. I'll futz with that, but if anyone has ideas, I'd def appreciate it.
     
  4. defied

    defied

    Joined:
    Dec 4, 2020
    Posts:
    17
    Alright, so it's a bit of a pain because I can't pull much information about the object itself, such as the Label or Tag info.
    I'm wondering if I'm butting my head up against a wall using cinemamachine as well?
     
  5. defied

    defied

    Joined:
    Dec 4, 2020
    Posts:
    17
    I think I sussed it out. Let me know if there's a cleaner way to do this.

    upload_2022-9-3_21-31-15.png
     
  6. defied

    defied

    Joined:
    Dec 4, 2020
    Posts:
    17
    Side note: I hate you, `while` loop.
    upload_2022-9-4_19-12-14.png
     
  7. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    Raycast will only return true on objects that have the ridged body component attached. so you could use a spherecast instead to detect any object.

    But I think you're looking for Game Object Get Game Object from the collider hit as shown below. get game object.PNG
     

    Attached Files:

  8. defied

    defied

    Joined:
    Dec 4, 2020
    Posts:
    17
    Thanks! I did end up getting the game object, but now it looks like maybe I can't use the equals value twice?
    See below how during runtime, if the state changes, you can see it's not changed on both connections. This feels like a bug as I'm effectively pulling one value into two different methods. Why would that get sticky?

    upload_2022-9-5_13-11-43.png
     

    Attached Files:

  9. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    Well here, you are attempting to take the mesh renderer component from the back of the set variable node.

    you would have to set the variable than get it again with a seperate node. and also don't need to reference the component directly only the game object. just keep at it and it'll click.


    here i use the find object node to get a reference of the game object that can be fetched later on down the line without needing to declare a var. if you're doing instanced prefabs then you'll want to use Transform Child Index. apparently it's faster too.

    but you can see the mesh renderer is directly referencing a game object not a component.

    does this help at all?
    Capture4.PNG
     
  10. defied

    defied

    Joined:
    Dec 4, 2020
    Posts:
    17
    It absolutely does! Thank you!

    D
     
  11. defied

    defied

    Joined:
    Dec 4, 2020
    Posts:
    17
    The diff it appears to me is that I don't need to find an object on start (although I could use this to find the player instead of declaring a var for it), as I am dynamically determining if an object is between the player and the camera.
    If there is, it stores the object in a var, disables the mesh renderer and when the object is no longer in the way, it will re-enable the mesh renderer.

    Eventually, I'll figure out how to make it so the object goes transparent (which I think I need to dig into material or shader editing for making those calls), but for now, this is very helpful.

    Thanks again,
    D
     
  12. unity_0DF4EB144C45323B4366

    unity_0DF4EB144C45323B4366

    Joined:
    Aug 2, 2022
    Posts:
    6
    Sorry, i cant provide anything to the discussion but I'm curious is the mesh render thing a performance thing?
    Do you do it to unload things not on screen and if so are there any threads going true on how it works :)?
     
  13. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    good stuff. yeah just takes some farting around with. needs more documentation or more details on the nodes themselves.
     
  14. defied

    defied

    Joined:
    Dec 4, 2020
    Posts:
    17
    It's a mid-hack until I get the code sorted. Eventually I'll have it tell the material/ shader to go transparent. It's so I can see the player behind objects while moving them around.
    I work in Infrastructure/product/software development, but not in C#, so whenever I get time to come back to my project, I've already forgotten half the stuff I've learned. Lol!

    This is me struggle-bussing through it.

    That was the first thing I noticed is that the descriptions for all the classes seems extremely minimal.

    Thanks again for your help, I appreciate it!
    D