Jump to content

Gaia Pro 2021 Change Player and Camera in Realtime


Casper

Recommended Posts

Hi, There are vehicles and characters in my project. When I press the exit button while driving my car in run time, a new prefab is loaded from the project and I switch to walking mode. The character's camera is also different. What I want to do is to change the player and camera in the Gaia system while in runtime. For this, I use the SetRuntimePlayerAndCamera function in GaiaApi. This function I wrote works and the Main Camera variable in the Gaia Global script on the Gaia Runtime object is updated. I can see it working when I go underwater. However, when I start walking, the grass does not load. The Main Player and Main Camera variables in the script called gaia scene player in the Gaia Player object are not updated (I don't know if they need to be changed). I don't get any errors in the console. How can I solve this?

 

Link to comment
Share on other sites

I'm not sure if I'm doing it right, but when I added these lines, the problem seems to be solved.
  Using.ProceduralWorlds.Flora;

FloraAutomationAPI.SetRenderCamera(newCamera);

It looks like I solved the problem with this function, unless I missed anything.

 I want to share the whole code, everything seems to be working correctly, but I'm not sure.  If verified, others may benefit from it.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ProceduralWorlds.Flora;

public class PlayerChangeRunTime : MonoBehaviour
{
    public bool changedPlayer=false;
    void Start()
    {
      
    }

    // Update is called once per frame
    void Update()
    {
       
        if(changedPlayer==false){
            GameObject newCharacter = GameObject.Find("Capsule");
            Camera newCamera = GameObject.Find("MainCamera").GetComponent<Camera>();
            Gaia.GaiaAPI.SetRuntimePlayerAndCamera(newCharacter, newCamera,true);
            FloraAutomationAPI.SetRenderCamera(newCamera);
            changedPlayer=true;
        }
    }
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Tell a friend

    Love Canopy - Procedural Worlds? Tell a friend!
  • Need help?

    We work with some of the biggest brands in global gaming, automotive, technology, and government to create environments, games, simulations, and product launches for desktop, mobile, and VR.

    Our unique expertise and technology enable us to deliver solutions that look and run better at a fraction of the time and cost of a typical project.

    Check out some of our non-NDA work in the Gallery, and then Contact Us to accelerate your next project!

×
×
  • Create New...