Set view to camera entity setted up in the editor with C++

So i've a camera in my level that i set up in the editor and it has some flow graph nodes for UI in it and i want to set its view by c++ but i don't undestend why m i getting a null pointer at m_pGameCameraEntity to store a camera entity that is in the level, but it get it's ID in m_EntityId? makes no sense how it gets the id if m_pGameCameraEntity it's null pointer?



Code: Select all

#pragma once
#include "IViewSystem.h"

struct RTSCamera


   //Member Functions
   void CreateRTSCamera();
   string GetLevelName();
   void SetViewParams(unsigned int XameraId, EntityId GameCameradId, IEntity *GameCamera);

   //Member Variables
   SViewParams m_CurViewParams;
   SViewParams m_NewViewParams;
   IViewSystem *m_pIViewSystem;
   IEntitySystem *m_pIEntitySystem;
   EntityId m_EntityId;
   IGameFramework *m_pGameFrameWork;
   IView *m_pRTSCameraView;
   IEntity *m_pGameCameraEntity;
   uint8 m_RTSCameraViewID;
   bool CameraExist;


Code: Select all

#include "StdAfx.h"
#include "RTSCamera.h"
#include "CryEntitySystem/IEntitySystem.h"
#include "CryGame/IGameFramework.h"

string RTSCamera::GetLevelName()
   //m_pGameCameraEntity = gEnv->pGame->GetIGameFramework();

   m_pGameFrameWork = g_pGame->GetIGameFramework();

   string levelName = m_pGameFrameWork->GetLevelName();

   return levelName;

void RTSCamera::CreateRTSCamera()
   //Assign the IViewSystem to a pointer named m_pIViewSystem
   m_pIViewSystem = gEnv->pGameFramework->GetIViewSystem();

   //Assign the IEntitySystem to a pointer named m_pIEntitySystem
   m_pIEntitySystem = gEnv->pSystem->GetIEntitySystem();

   //Assign camera entity in the game world to a pointer named m_pGameCameraEntity
   m_pGameCameraEntity = m_pIEntitySystem->FindEntityByName("GameCamera");

   //Get GameCamera's EntityId and store it into a variable named m_EntityId
   m_EntityId = m_pGameCameraEntity->GetId();

   //Active the Camera Entity

   //Create a new View and assign it to a pointer named m_pIView
   m_pRTSCameraView = m_pIViewSystem->CreateView();

   //Get the view Id of our new camera and assign it to a variable named RTSCameraViewId
   m_RTSCameraViewID = m_pIViewSystem->GetViewId(m_pRTSCameraView);

   //Remove the currently active view

   //Set our new view as the active one

   //Give Initial values to our camera
   SetViewParams(m_RTSCameraViewID, m_EntityId, m_pGameCameraEntity);

   //Set View params for our camera

   //Link our new view to the game camera entity in our world

void RTSCamera::SetViewParams(unsigned int CameraId, EntityId GameCameraId, IEntity *GameCamera)
   m_CurViewParams.position = GameCamera->GetWorldPos();
   m_CurViewParams.rotation = GameCamera->GetWorldRotation();
   m_CurViewParams.nearplane = 0.0f;
   m_CurViewParams.fov = 0.6f;
   m_CurViewParams.viewID = CameraId;
   m_CurViewParams.groundOnly = false;
   m_CurViewParams.shakingRatio = 0.0f;
   m_CurViewParams.currentShakeQuat = IDENTITY;
   m_CurViewParams.currentShakeShift = ZERO;
   m_CurViewParams.idTarget = GameCameraId;
   m_CurViewParams.targetPos = GameCamera->GetWorldPos();
   m_CurViewParams.angleVel = 0.0f;
   m_CurViewParams.vel = 0.0f;
   m_CurViewParams.dist = 0.0f;
   m_CurViewParams.blend = false;

The code is initialize on CGame::Update function in Game.cpp

Code: Select all

string LevelName = RTSCamera_01.GetLevelName();
   if (LevelName != EmptyString)
      CryLogAlways("CRYLOG: Level "+ LevelName +" Loaded!");
      EmptyString = LevelName;

It compiles and runs fine, i load the level but the view is not set on the camera i set up in the editor, the view goes to the usual first person and the code only breaks when i click exit level, i've made sure the code runs when the level is loaded by logging the function initialization, and yes i've done export to engine in the editor.

fun fact: if i enter in game mode in the editor all workes just fine -_-'

Please give me some lights!!! thanks.

Re: Set view to camera entity setted up in the editor with C++

fkhaller wrote:Where do you name and register the entity as gamecamera? As far as I am aware all entities need to either extend ISimpleExtention or CNativeEntityBase and all camera's need to extend IGameObjectView.

GameCamera is the camera name on the editor, i didn't find anything related to ISimpleExtention nor CNativeEntityBase and IGameObjectView is for updating and i already have something that takes care of that, i beleve that you didn't understood the problem, i'm going to simplefy it, How to store an Entity in a variable?

Who is online

Users browsing this forum: No registered users and 2 guests