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. Dismiss Notice

Vegetation Studio Camera Change

Discussion in 'Editor & General Support' started by Hawk0077, May 8, 2018.

  1. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    788
    Hi, I am trying to get Vegetation Studio (VS) to change camera from the main camera tyo the car camera when I get in the car. To make sure vegetation shows with the in car camera.

    I recently did something similar with Enviro with help from someone on the forums here at unity.

    The developer of VS siad this: (which isnt very helpful to me as a non C~ coder).


    "to change the camera in script get a reference to the Vegetation System component. Then call SetCamera(camera) on this. You can also do it from the static function on the VegetationStudioManager".

    Regarding the first part the "Enviro" changes I made were... adding the two EnviroSky.instance.ChangeFocus lines below to the existing car camera script.

    Code (CSharp):
    1. void Update()
    2.     {
    3.  
    4.         // If it's active, enable the camera. If it's not, disable the camera.
    5.         if (!isRendering)
    6.         {
    7.             if (cam.gameObject.activeInHierarchy)
    8.             {
    9.                 cam.gameObject.SetActive(false);
    10.                 EnviroSky.instance.ChangeFocus(EnviroSky.instance.Player, Camera.main);
    11.             }
    12.             return;
    13.         }
    14.         else
    15.         {
    16.             if (!cam.gameObject.activeInHierarchy)
    17.             {
    18.                 cam.gameObject.SetActive(true);
    19.                 EnviroSky.instance.ChangeFocus(EnviroSky.instance.Player, cam);
    20.             }
    21.         }

    Now in all honesty I dont have a clue what the VS developer was meaning.

    Any help appreciated.

    PS; I presume that it is the same car camera script I need to add the code changes to? Whatever they may be?

    Many thanks and appreciation.
     
  2. travakin

    travakin

    Joined:
    Apr 20, 2012
    Posts:
    7
    Hi,

    I was actually trying to find an answer to this same question when I found this. Based on what you posted, I was able to write this script that finds a vegetation system in the scene and sets the camera.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5. using AwesomeTechnologies;
    6.  
    7. [RequireComponent(typeof(Camera))]
    8. public class SetVegetationCamera : MonoBehaviour {
    9.  
    10.     //This is the reference to the vegetation system
    11.     VegetationSystem vegetationSystem;
    12.  
    13.     // Use this for initialization
    14.     void Start () {
    15.  
    16.         //Get the vegetation system from the scene
    17.         vegetationSystem = FindObjectOfType<VegetationSystem>();
    18.  
    19.         //Cancel if there is no vegetation system
    20.         if (vegetationSystem == null)
    21.             return;
    22.  
    23.         //Set the camera
    24.         vegetationSystem.SetCamera(this.GetComponent<Camera>());
    25.     }
    26. }
    27.  
    Just put this script on your car camera.

    Hope that helps!
     
    AggressiveMastery and Hawk0077 like this.
  3. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    788

    wow, awesome. I will give it a go right now.

    Thanks, I will let you know how it goes in about 15 mins.
     
  4. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    788
    Thanks for the effort but that actually didnt work.

    I'm not a qualified C# developer so I can only guess... But I would most likely need to add a similar script to the character camera to change the camera back to the main camera?

    I am only guessing though. Either way the script didnt work this time.

    But thanks for the help, I appreciate it. You set me on the path to a solution I think. Thanks for that.
     
  5. travakin

    travakin

    Joined:
    Apr 20, 2012
    Posts:
    7
    It occurs to me that your program is likely enabling/disabling the cameras between the car and your main camera, is that right? Mine works because in my scene, player objects are being created and destroyed between camera changes. In your case, you might want to switch from using the Start function to the OnEnable function, with the same code inside, and put the script on both your car camera and your main camera. That way the active camera is always the one that's being set in the vegetation system.
     
    Hawk0077 likes this.
  6. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    788
    Thanks I will take a look at that to see if I can get it working.

    Much appreciated.
     
  7. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    788
    As far as I believe the Player (using main camera) gets destroyed when he enters the car (using RCCCamera). Then the Player appears again as the camera switches back to the Main Camera.

    The developer may well get back to me with a solution but its been 3 days so far. Fingers crossed.
     
  8. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    788
    Changing Start to OnEnable didnt work Im afraid.

    I am not sure what to do now. Unless I give fiverr a visit. lol
     
  9. AggressiveMastery

    AggressiveMastery

    Joined:
    Nov 19, 2018
    Posts:
    206
    I have Veg Studio Pro, and got this working in the FPS Sample with a modified version of your script @travakin & @Hawk0077 !

    Thank you, Here is the ... Work in Progress with comments. Sorry future everyone, for how ugly this is. But this is an older post after all.

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using AwesomeTechnologies.BillboardSystem;
    4. using AwesomeTechnologies.Utility;
    5. using AwesomeTechnologies.Utility.Culling;
    6. using AwesomeTechnologies.Utility.Quadtree;
    7. using AwesomeTechnologies.Vegetation.Masks;
    8. using AwesomeTechnologies.Vegetation.PersistentStorage;
    9. using AwesomeTechnologies.VegetationStudio;
    10. using AwesomeTechnologies.VegetationSystem.Wind;
    11. using Unity.Collections;
    12. using Unity.Jobs;
    13. #if UNITY_EDITOR
    14. using UnityEditor;
    15. #endif
    16. using UnityEngine;
    17. using UnityEngine.Profiling;
    18. using UnityEngine.Rendering;
    19.  
    20. namespace AwesomeTechnologies.VegetationSystem
    21. {
    22.  
    23.         //[RequireComponent(typeof(Camera))]
    24.  
    25.         /// <summary>
    26.         /// This script is on the spawned camera of the player, on the client. It tells the veg system that this camera needs to be added and view the vegitation. Aggm-9_24_2019
    27.         /// </summary>
    28.  
    29.         public class SetVegetationCamera : MonoBehaviour
    30.         {
    31.             public Camera myCamera;  //place this script on the spawned camera prefab, then in the prefab drag that camera to this variable
    32.             public VegetationSystemPro vegetationSystempro;  //we have pro, so the class is also named pro, lol
    33.             //what camera to assign
    34.  
    35.             //This is the reference to the vegetation system
    36.             //VegetationSystem vegetationSystem;
    37.  
    38.             // Use this for initialization
    39.             void Start()
    40.             {
    41.             //Get the vegetation system from the scene
    42.  
    43.             vegetationSystempro = FindObjectOfType<VegetationSystemPro>();
    44.  
    45.             vegetationSystempro.AddCamera(myCamera, true, false, false); //the 3 end bools are: render directly to camera, billboards_only, disable_frustrum.
    46.  
    47.             Debug.Log("set this camera ammmmmsege : " + myCamera);
    48.            
    49.  
    50.                 //Cancel if there is no vegetation system
    51.                 //if (vegetationSystem == null)
    52.                 // return;
    53.  
    54.                 //Set the camera
    55.                 //vegetationSystem.SetCamera(myCamera);
    56.             }
    57.         }
    58.  
    59. }
     
    Last edited: Sep 25, 2019
    Hawk0077 likes this.
  10. Hawk0077

    Hawk0077

    Joined:
    Nov 6, 2017
    Posts:
    788
    Much appreciated, thanks. I did get it going originally bust since then I have been upgrading everything and so will return to your response when I am back up to speed, so thanks.
     
  11. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    831
    I appreciate this! Having the same issue with camera switching from fpc to tpc with vsp.
    Going to give it a try.
     
    AggressiveMastery likes this.
  12. AggressiveMastery

    AggressiveMastery

    Joined:
    Nov 19, 2018
    Posts:
    206
    I am now playing with the DOTS Sample Project ( https://forum.unity.com/threads/dots-sample.796308/ )

    And Have modified this script, and have it on the veg studio game object, instead of down on the camera/player itself. Since in the DOTS sample, having a mono script on the spawned ... well it caused crashes :)

    But finding the camera from the veg studio object did not. Simple find and place script.

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using AwesomeTechnologies.BillboardSystem;
    4. using AwesomeTechnologies.Utility;
    5. using AwesomeTechnologies.Utility.Culling;
    6. using AwesomeTechnologies.Utility.Quadtree;
    7. using AwesomeTechnologies.Vegetation.Masks;
    8. using AwesomeTechnologies.Vegetation.PersistentStorage;
    9. using AwesomeTechnologies.VegetationStudio;
    10. using AwesomeTechnologies.VegetationSystem.Wind;
    11. using Unity.Collections;
    12. using Unity.Jobs;
    13. #if UNITY_EDITOR
    14. using UnityEditor;
    15. #endif
    16. using UnityEngine;
    17. using UnityEngine.Profiling;
    18. using UnityEngine.Rendering;
    19.  
    20. namespace AwesomeTechnologies.VegetationSystem
    21. {
    22.  
    23.         //[RequireComponent(typeof(Camera))]
    24.  
    25.         /// <summary>
    26.         /// This script is on the spawned camera of the player, on the client. It tells the veg system that this camera needs to be added and view the vegitation. Aggm-9_24_2019
    27.         /// Updated 2020- now this sits on the Veg Studio Script, and runs on late update, to tag the player camera clone and assign it.
    28.         /// </summary>
    29.  
    30.         public class SetVegetationCamera : MonoBehaviour
    31.         {
    32.         public Camera myCamera; //place this script on the spawned camera prefab, then in the prefab drag that camera to this variable
    33.         public VegetationSystemPro vegetationSystempro;  //we have pro, so the class is also named pro, lol
    34.         public GameObject CameraObject;
    35.             //what camera to assign
    36.             //since this is a mono script, lets try to make it less impactful with late update
    37.             void LateUpdate()
    38.         {
    39.             //Get the vegetation system from the scene
    40.             //Get the Camera ...
    41.  
    42.             //If our camera object is null,
    43.             if (CameraObject == null)
    44.             {
    45.                 //lets find one.
    46.                 CameraObject = GameObject.Find("PlayerCamera(Clone)");
    47.  
    48.                 //if we have found a camera
    49.                 if (CameraObject != null)
    50.                 {
    51.                     //lets assign the camera, by getting it from the game object.
    52.                     myCamera = CameraObject.GetComponent<Camera>();
    53.                     //FindObjectOfType<PlayerCamera>();
    54.  
    55.                     //vegetationSystempro = FindObjectOfType<VegetationSystemPro>();
    56.  
    57.                     //lets add the camera
    58.                     vegetationSystempro.AddCamera(myCamera, true, false, false); //the 3 end bools are: render directly to camera, billboards_only, disable_frustrum.
    59.  
    60.                     Debug.Log("set this camera ammmmmsege : " + myCamera);
    61.                 }
    62.              
    63.             }
    64.                 //Cancel if there is no vegetation system
    65.                 //if (vegetationSystem == null)
    66.                 // return;
    67.  
    68.                 //Set the camera
    69.                 //vegetationSystem.SetCamera(myCamera);
    70.             }
    71.         }
    72.  
    73. }

    Cheers
    Micah
     

    Attached Files:

    dsilverthorn likes this.
  13. AggressiveMastery

    AggressiveMastery

    Joined:
    Nov 19, 2018
    Posts:
    206
    I'm not sure what happens with multiple players, so you may want to check that. i will and will try to update here, but I may forget...
     
    dsilverthorn likes this.
  14. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    831
    Excellent. Thanks. I'm only doing single player right now, who knows where it may lead.

    I am using Invector with a First Person add-on by @sjm-tech and he directed me to your script in this forum. So I'm trying to switch from 3rd to 1st, but can only get one view working with VSP due to the second camera being instantiated and not in the scene.
    Going to give your solution a try to see if I can make that work for me.
    I really appreciate you sharing it!
     
  15. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    831
    Ok. I'm looking it over, but having run it yet. Do just add the camera in the scene (first person cam) into "My Camera" and the camera that will be created when called (third person cam) into "Camera Object"?
     
  16. AggressiveMastery

    AggressiveMastery

    Joined:
    Nov 19, 2018
    Posts:
    206
    Well my example is for when the camera does not exist, but rather spawns from a prefab at runtime, so you have to look for it at run time from something that we know exists(the veg studio game object, since we know that exists.)

    If you have static cameras, Meaning you can reference the cameras in the editor view. Just drag them into the "cameras" part of the Veg Studio Config Screen, and you can have 1 Veg Studio instance render to multiple cameras. Now, I assume that would work between scenes, as long as the scenes are loaded. If they get loaded at runtime, then you need this type of script, to find them during runtime.

    Lennart is great at helping (*Veg Studio Author.) I would recommend hitting Lennart on his discord.

    Discord for Veg Studio:

    https://discordapp.com/invite/Fbn4QP3

    Veg Studio has some "auto select camera" options, but i've disabled them. This may be something he already has a solution for... For staic Cameras in different scenes.

    Cheers
    Micah
     
  17. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    831
    That is what I need.
    I start with a camera in the scene. FPC
    And then spawn the TPC camera when switching.
    The FPC camera may be destroyed during the switch too and then respawned when switching, I’m not sure because I haven’t gone theough it completely. But the FPC does retain veg when switching back, it’s just the TPC that doesn’t get any veg.
    So looks like your solution will work.
    I was unable to get to it yesterday but will try it today.

    I did send Lennart a message on Discord but he hasn’t been back yet to answer.
     
    AggressiveMastery likes this.
  18. Xialya

    Xialya

    Joined:
    Oct 4, 2015
    Posts:
    52
    Heya. :)

    Looks like only the pro version handles multiple camera?
    I'm working on a split-screen game and just upgrading for the pro version for this feature is not really fun.

    Is there a workaround?
     
  19. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    935
    Hi. Does anyone has an example how to set an camera in Vegetation Studio Pro per script?

    I have the camera as GUID Cross Scene Reference from the main scene.