Net bindable component undeclared identifier.

Hello, I’m trying to create a net bindable component with some RPCs on the replica chunk and a requests EBus to call them.
The RPCs’ handlers are implemented on the component.
But it doesn’t compile, I have an C2065 error, and it says that I have an undeclared identifier for my component class.

Can someone help me to understand what’s the problem ?

Thanks. Here’s is my code :

TestComponent.h


#pragma once
#include <AzCore\Component\Component.h>
#include "Source\EBus\TestComponentRequests.h"
#include <AzFramework/Network/NetBindable.h>
#include "Source\Replica\TestComponentReplicaChunk.h"
namespace Test
{
class TestComponent :
public AZ::Component,
public TestComponentRequestsBus::Handler,
public AzFramework::NetBindable
{
public: AZ_COMPONENT(TestComponent, "{91B45DE6-2151-4E0F-BEBD-F2C69927F9C1}", AzFramework::NetBindable);
static void Reflect(AZ::ReflectContext* context);
void Init() override {}
void Activate() override;
void Deactivate() override;
GridMate::ReplicaChunkPtr GetNetworkBinding() override;
void SetNetworkBinding(GridMate::ReplicaChunkPtr chunk) override;
void UnbindFromNetwork() override;
void RPCCall() override;
bool RPCHandler(int dummy, const GridMate::RpcContext& context);
private:
GridMate::ReplicaChunkPtr m_replicaChunk; };
}

TestComponentReplicaChunk.h


#pragma once
#include <AzFramework\Network\NetBindable.h>
#include "Source\Components\TestComponent.h"
namespace Test
{
class TestComponentReplicaChunk : public GridMate::ReplicaChunkBase
{
public:
AZ_CLASS_ALLOCATOR(TestComponentReplicaChunk, AZ::SystemAllocator, 0);
static const char* GetChunkName() { return "TestComponentReplicaChunk"; }
TestComponentReplicaChunk() :
RPC("RPC")
{}
bool IsReplicaMigratable() { return false; }
GridMate::Rpc<GridMate::RpcArg<int>>::BindInterface<TestComponent, &TestComponent::RPCHandler, GridMate::RpcDefaultTraits> RPC;
};
}

TestComponentRequests.h


#pragma once
#include <AzCore\Component\ComponentBus.h>
namespace Test
{
class TestComponentRequests : public AZ::ComponentBus
{
public:
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
virtual void RPCCall() = 0;
};
using TestComponentRequestsBus = AZ::EBus<TestComponentRequests>;
}

TestComponent.cpp


#include <StdAfx.h>
#include "TestComponent.h"
#include <AzCore\Serialization\SerializeContext.h>
#include <AzCore\Serialization\EditContext.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzFramework\Network\NetworkContext.h>
#include <AzCore\Component\Entity.h>
#include <GridMate/Replica/ReplicaFunctions.h>
#include <Windows.h>
namespace Test
{
void TestComponent::Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<TestComponent, AzFramework::NetBindable, AZ::Component>()
->Version(1)
;
AZ::EditContext* editContext = serializeContext->GetEditContext();
if (editContext)
{ editContext->Class<TestComponent>("TestComponent", "Game Rules Component")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Category, "Accomodation Project Components")
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game"))
;
}
}
AZ::BehaviorContext* behaviourContext = azrtti_cast<AZ::BehaviorContext*>(context);
if (behaviourContext)
{
behaviourContext->EBus<TestComponentRequestsBus>("TestComponentRequestsBus")
->Event("RPCCall", &TestComponentRequestsBus::Events::RPCCall)
;
}
AzFramework::NetworkContext* netContext = azrtti_cast<AzFramework::NetworkContext*>(context);
if (netContext)
{
netContext->Class<TestComponent>()
->Chunk<TestComponentReplicaChunk>()
->RPC<TestComponentReplicaChunk, TestComponent>("RPC", &TestComponentReplicaChunk::RPC)
;
}
}
void TestComponent::Activate()
{
TestComponentRequestsBus::Handler::BusConnect(m_entity->GetId());
}
void TestComponent::Deactivate()
{
TestComponentRequestsBus::Handler::BusDisconnect();
}
GridMate::ReplicaChunkPtr TestComponent::GetNetworkBinding()
{
TestComponentReplicaChunk* replicaChunk = GridMate::CreateReplicaChunk<TestComponentReplicaChunk>();
replicaChunk->SetHandler(this);
m_replicaChunk = replicaChunk;
return m_replicaChunk;
}
void TestComponent::SetNetworkBinding(GridMate::ReplicaChunkPtr chunk)
{
chunk->SetHandler(this);
m_replicaChunk = chunk;
}
void TestComponent::UnbindFromNetwork()
{
m_replicaChunk->SetHandler(nullptr);
m_replicaChunk = nullptr;
}
void TestComponent::RPCCall()
{
TestComponentReplicaChunk* replicaChunk = static_cast<TestComponentReplicaChunk*>(m_replicaChunk.get());
replicaChunk->RPC(0);
}
bool TestComponent::RPCHandler(int dummy, const GridMate::RpcContext& context)
{
OutputDebugString("RPCHandler");
return true;
}
}

Have you added these files to your WAF build config, and also to your Module file?

Yes, all these files are added to the waf_file and my component descriptor is added to my module file.

Hi @Leonard,

Are you still having issues with this? Are you currently using 1.10, or 1.11 now?