Spawning player after loading new map

#1
I'm wondering what is the underlying logic when the engine load a new map.

currently we are following the template setup, spawning player in OnClientConnectionReceived(int channelId, bool bIsReset) in GamePlugin.cpp

Code: Select all

SEntitySpawnParams spawnParams; spawnParams.pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("schematyc::schematyc::sm_player"); spawnParams.sName = "Player"; // Set local player details if (m_players.size() == 0 && !gEnv->IsDedicated()) { spawnParams.id = LOCAL_PLAYER_ENTITY_ID; spawnParams.nFlags |= ENTITY_FLAG_LOCAL_PLAYER; IEntity* pPlayerEntity = nullptr; CPlayerComponent* pPlayer = nullptr; // Spawn the player entity if (pPlayerEntity = gEnv->pEntitySystem->SpawnEntity(spawnParams)) { // Set the local player entity channel id, and bind it to the network so that it can support Multiplayer contexts pPlayerEntity->GetNetEntity()->SetChannelId(channelId); pPlayerEntity->GetNetEntity()->BindToNetwork(); // Create the player component instance pPlayer = pPlayerEntity->GetOrCreateComponentClass<CPlayerComponent>(); // Push the component into our map, with the channel id as the key m_players.emplace(std::make_pair(channelId, pPlayerEntity->GetId())); }
When we load a new map, should we spawn a new player and redo all the bindings? and does the system automatically destroy the old player?

Thank you!

Who is online

Users browsing this forum: No registered users and 1 guest