Activate() Component

0

I'm not exactly sure what I'm doing wrong, but I can't get my PlayerControllerComponent to Activate. This is called in GameStartup:

EBUS_EVENT(AZ::ComponentApplicationBus, RegisterComponentDescriptor, Vx::PlayerControllerComponent::CreateDescriptor()); //Added from Multiplayer example

I tried a few different things, between switching from using ActionMapping / IInput to capture keyboard / mouse controls.

Everything compiles fine, and can get into the level with the actor initialized and custom settings:

	bool TestGameRules::OnClientConnect(ChannelId channelId, bool isReset)
{
return gEnv->pGame->GetIGameFramework()->GetIActorSystem()->CreateActor(channelId, "Player", "Actor", Vec3(100, 100, 30), Quat(Ang3(0, 0, 0)), Vec3(1, 1, 1)) != nullptr;
}

REMOVEDUPLOAD

And realized that no where is this being called :

    void PlayerControllerComponent::Activate()
{
AZ::TickBus::Handler::BusConnect();
IActionMapManager* actionMapManager = gEnv->pGame->GetIGameFramework()->GetIActionMapManager();
if (actionMapManager)
actionMapManager->AddExtraActionListener(this, "player");
}

Hence, no tickbus connect, or actionMap listener.

Debugging seems to go through:

ComponentDescriptorHelper::ComponentDescriptorHelper()
PlayerControllerComponent::Reflect()
ComponentApplication::RegisterComponentDescriptor()

but then continues through the normal CryAction loading / game loop.

I've also regenerated a UUID, and searched for name conflicts; thinking that it might be an issue, but still no luck:

AZ_COMPONENT(PlayerControllerComponent, "{23166B3B-845C-4B27-B603-8E44C4CA7E3C}");

I must be doing something wrong.

Does anyone have anything I've missed from the documentation that would cause this not to Activate()?

EDIT: I see the PlayerController component in the Editor, so it's being registered. It seems I need to figure out how to attach it to the C++ Actor I created.

asked 7 years ago164 views
7 Answers
0
Accepted Answer

It seems like the answer is, you can't... directly? The Actor system isn't setup to accept the new AZ::Entity. It looks like the View system has been hacked a bit to implement views for Entities/Components, but not much else regarding gameplay systems. I'd imagine that there will be an actor component or something, instead of having your Entity inherit from IActor.

Researching further, it seems the Entities do nothing (I should say, no gameplay logic) but contain Components. I had problems inheriting from Entity, since you can't access framework components (friend relationship with only the Entity class.) And when you instantiate an Entity manually through GameContextBus or EntityBus, they are activated immediately, without the ability to add components; unless you want to activate, deactivate, create components, activate. Then it gets added to the root slice? I'm not clear on that one, but I don't think that's where it should be?

So, from what I understand, the work flow currently should be to add an Entity and Components in the Editor, save it as a dynamic slice file. Then in the code, instantiate the slice file? It's almost like Amazon has gone out of their way to make it inconvenient to create Entities by code. I'm new to C++ so take this all with a grain of salt. I could be missing the big picture.

At the moment to use all the tools to make a game, you will be relying on the old Entity / GameObjects and extensions system. Which will all be changed, and need to be recoded when Amazon implements the new system. Unless you're impatient and have time to re implement the functionality of these singleton systems.

Please weigh in if I'm missing the mark completely!

answered 7 years ago
0

I think the controller isn't attaching to the actor entity, as you said. Do you know the proper way to attach a component to an entity that was created by C++? I'm creating the actor on-the-fly when TestGameRules::OnConnect() is called.

I did as you said, inserted a component entity in the level with the editor, and assigned the custom PlayerController, and a mesh. Activate() is still not being called. The Controller is derived from AZ::Component.

It's a bit frustrating, having Component/Entity classes in AzCore:: and CryAction::. Since the actor system is using IEntity, and the component is using Entity. It's not very straightforward, and it a bit confusing.

answered 7 years ago
0

Now I'm a bit more confused... the MultiplayerProject comes with a PlayerController, and it doesn't seem like it's used either. I can't find a reference to it anywhere. Can someone explain to me how a component like this is supposed to be initialized through C++?

answered 7 years ago
0

Maybe the component isn't attached to an entity? Create an entity in an empty level by right-clicking the terrain then selecting Create Component Entity. The Entity Outliner should open (or open it), and select the entity (probably called Entity1). In the Entity Inspector, click the Add Component... button, then select the component you want to attach to it from the list. The Activate() function in the component should get called.

If not, maybe the component has a dependency that is not present? From [1]: "Called when the owning entity is being activated. The system calls your component's Activate() function only if all dependent or required services are present. Your Activate function is always called after any components that it depends on. In addition the component makeup of an entity never changes while the entity is active, so it is safe to cache pointers or references to other components on the entity in performance-critical situations."

Or maybe PlayerControllerComponent is not derived from AZ::Component as in the example? (Although how that would compile is another question). From [1]: "Every component must include AZ::Component somewhere in its inheritance ancestry."

If it's none of those, we can investigate further!

[1] http://docs.aws.amazon.com/lumberyard/latest/developerguide/component-entity-system-create-component.html

answered 7 years ago
0

Can you give us the whole class code?

answered 7 years ago
0

It's the same class as in the MultiplayerProject example, with new UUID and different namespace to match my project. The internal OnTick() is a little different but, other than that it's exactly the same. The funny thing is, I can't find anywhere in the MultiplayerExample that this PlayerController is used and Activated either...All the Input controls seem to be coming from Flowgraph, however it's there in the code.

answered 7 years ago
0

This answer was priceless for me. After around 10 days of tinkering I also came to same conclusion. But I really didn't trust my own judgement until I saw your answer.

Thank you mate. Seriously.

answered 7 years ago

This post is closed: Adding new answers, comments, and votes is disabled.