5.4 Preview 3 | c++ | It is possible to get schematyc object from scene as a player in code (with networking) ?

#1
Hi, I am trying to get schematyc object as a player from code as (it's modified rolling ball template):

GamePlugin.cpp:

Code: Select all

bool CGamePlugin::OnClientConnectionReceived(int channelId, bool bIsReset)
{
   if (IEntity* pPlayerEntity = gEnv->pEntitySystem->FindEntityByName("schematic::player_sch-1"))
   {
      string player_name = string().Format("Player%" PRISIZE_T, m_players.size());
      pPlayerEntity->SetName(player_name);
      pPlayerEntity->AddFlags(ENTITY_FLAG_NEVER_NETWORK_STATIC);

      if (m_players.size() == 0 && !gEnv->IsDedicated())
      {
         pPlayerEntity->SetObjectID(LOCAL_PLAYER_ENTITY_ID);
         pPlayerEntity->AddFlags(ENTITY_FLAG_LOCAL_PLAYER);
      }

      // Create the player component instance
      CPlayerComponent* pPlayer = pPlayerEntity->GetOrCreateComponent<CPlayerComponent>();

      // 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();

      // Push the component into our map, with the channel id as the key
      m_players.emplace(std::make_pair(channelId, pPlayerEntity->GetId()));
   }
   
   return true;
}


With this code I get no errors but screen is black (the schematyc object is found at map).
If I change schematyc object to entity one everything works correctly.

Re: 5.4 Preview 3 | c++ | It is possible to get schematyc object from scene as a player in code (with networking) ?

#2
Hey,

Since Schematyc is still in development, it's not feature complete yet and we have to improve certain systems. But what you can do for now, is spawning the Schematyc entity directly in the OnClientConnectionReceived function. Something like this:

Code: Select all

bool CGamePlugin::OnClientConnectionReceived(int channelId, bool bIsReset)
{
   // Connection received from a client, create a player entity and component
   SEntitySpawnParams spawnParams;
   spawnParams.pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("schematyc::entities::player");  // put in your name of the player schematyc class here.
   spawnParams.sName = "Player";
   spawnParams.nFlags |= ENTITY_FLAG_NEVER_NETWORK_STATIC;
   
   // Set local player details
   if (m_players.size() == 0 && !gEnv->IsDedicated())
   {
      spawnParams.id = LOCAL_PLAYER_ENTITY_ID;
      spawnParams.nFlags |= ENTITY_FLAG_LOCAL_PLAYER;
   }

   // Spawn the player entity
   if (IEntity* 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();

      // Push the component into our map, with the channel id as the key
      m_players.emplace(std::make_pair(channelId, pPlayerEntity->GetId()));
   }

   return true;
}


Cheers,
Alex

Re: 5.4 Preview 3 | c++ | It is possible to get schematyc object from scene as a player in code (with networking) ?

#4
Hey Alex,

It works as you write:

Code: Select all

spawnParams.pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("schematyc::Entities::player");  // put in your name of the player schematyc class here.
IEntity* pPlayerEntity = gEnv->pEntitySystem->SpawnEntity(spawnParams);


Also it works for entity instance:

Code: Select all

IEntity* pPlayerEntity = gEnv->pEntitySystem->FindEntityByName("player")


The black screen was by my mistaken setup camera out of the world.

Thank you very much for help :)

Cheers,
Jan

Who is online

Users browsing this forum: No registered users and 1 guest

cron