Vegetation Studio Camera Change

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.

void Update()
    {

        // If it's active, enable the camera. If it's not, disable the camera.
        if (!isRendering)
        {
            if (cam.gameObject.activeInHierarchy)
            {
                cam.gameObject.SetActive(false);
                EnviroSky.instance.ChangeFocus(EnviroSky.instance.Player, Camera.main);
            }
            return;
        }
        else
        {
            if (!cam.gameObject.activeInHierarchy)
            {
                cam.gameObject.SetActive(true);
                EnviroSky.instance.ChangeFocus(EnviroSky.instance.Player, cam);
            }
        }

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.

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.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using AwesomeTechnologies;

[RequireComponent(typeof(Camera))]
public class SetVegetationCamera : MonoBehaviour {

    //This is the reference to the vegetation system
    VegetationSystem vegetationSystem;

    // Use this for initialization
    void Start () {

        //Get the vegetation system from the scene
        vegetationSystem = FindObjectOfType<VegetationSystem>();

        //Cancel if there is no vegetation system
        if (vegetationSystem == null)
            return;

        //Set the camera
        vegetationSystem.SetCamera(this.GetComponent<Camera>());
    }
}

Just put this script on your car camera.

Hope that helps!

2 Likes

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

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

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.

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.

1 Like

Thanks I will take a look at that to see if I can get it working.

Much appreciated.

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.

Changing Start to OnEnable didnt work Im afraid.

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

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.

using System;
using System.Collections.Generic;
using AwesomeTechnologies.BillboardSystem;
using AwesomeTechnologies.Utility;
using AwesomeTechnologies.Utility.Culling;
using AwesomeTechnologies.Utility.Quadtree;
using AwesomeTechnologies.Vegetation.Masks;
using AwesomeTechnologies.Vegetation.PersistentStorage;
using AwesomeTechnologies.VegetationStudio;
using AwesomeTechnologies.VegetationSystem.Wind;
using Unity.Collections;
using Unity.Jobs;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.Rendering;

namespace AwesomeTechnologies.VegetationSystem
{
 
        //[RequireComponent(typeof(Camera))]

        /// <summary>
        /// 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
        /// </summary>

        public class SetVegetationCamera : MonoBehaviour
        {
            public Camera myCamera;  //place this script on the spawned camera prefab, then in the prefab drag that camera to this variable
            public VegetationSystemPro vegetationSystempro;  //we have pro, so the class is also named pro, lol
            //what camera to assign

            //This is the reference to the vegetation system
            //VegetationSystem vegetationSystem;

            // Use this for initialization
            void Start()
            {
            //Get the vegetation system from the scene

            vegetationSystempro = FindObjectOfType<VegetationSystemPro>();

            vegetationSystempro.AddCamera(myCamera, true, false, false); //the 3 end bools are: render directly to camera, billboards_only, disable_frustrum.

            Debug.Log("set this camera ammmmmsege : " + myCamera);
            

                //Cancel if there is no vegetation system
                //if (vegetationSystem == null)
                // return;

                //Set the camera
                //vegetationSystem.SetCamera(myCamera);
            }
        }
 
}
1 Like

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.

I appreciate this! Having the same issue with camera switching from fpc to tpc with vsp.
Going to give it a try.

1 Like

I am now playing with the DOTS Sample Project ( https://discussions.unity.com/t/769712 )

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 :slight_smile:

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

using System;
using System.Collections.Generic;
using AwesomeTechnologies.BillboardSystem;
using AwesomeTechnologies.Utility;
using AwesomeTechnologies.Utility.Culling;
using AwesomeTechnologies.Utility.Quadtree;
using AwesomeTechnologies.Vegetation.Masks;
using AwesomeTechnologies.Vegetation.PersistentStorage;
using AwesomeTechnologies.VegetationStudio;
using AwesomeTechnologies.VegetationSystem.Wind;
using Unity.Collections;
using Unity.Jobs;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.Rendering;

namespace AwesomeTechnologies.VegetationSystem
{
  
        //[RequireComponent(typeof(Camera))]

        /// <summary>
        /// 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
        /// Updated 2020- now this sits on the Veg Studio Script, and runs on late update, to tag the player camera clone and assign it.
        /// </summary>

        public class SetVegetationCamera : MonoBehaviour
        {
        public Camera myCamera; //place this script on the spawned camera prefab, then in the prefab drag that camera to this variable
        public VegetationSystemPro vegetationSystempro;  //we have pro, so the class is also named pro, lol
        public GameObject CameraObject;
            //what camera to assign
            //since this is a mono script, lets try to make it less impactful with late update
            void LateUpdate()
        {
            //Get the vegetation system from the scene
            //Get the Camera ...

            //If our camera object is null,
            if (CameraObject == null)
            {
                //lets find one.
                CameraObject = GameObject.Find("PlayerCamera(Clone)");

                //if we have found a camera
                if (CameraObject != null)
                {
                    //lets assign the camera, by getting it from the game object.
                    myCamera = CameraObject.GetComponent<Camera>();
                    //FindObjectOfType<PlayerCamera>();

                    //vegetationSystempro = FindObjectOfType<VegetationSystemPro>();

                    //lets add the camera
                    vegetationSystempro.AddCamera(myCamera, true, false, false); //the 3 end bools are: render directly to camera, billboards_only, disable_frustrum.

                    Debug.Log("set this camera ammmmmsege : " + myCamera);
                }
              
            }
                //Cancel if there is no vegetation system
                //if (vegetationSystem == null)
                // return;

                //Set the camera
                //vegetationSystem.SetCamera(myCamera);
            }
        }
  
}

Cheers
Micah

5391099--546726--vegcamupdate.PNG

1 Like

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…

1 Like

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!

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”?

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:

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

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.

1 Like

Heya. :slight_smile:

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?

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.