- Mais recentes
- Mais votos
- Mais comentários
Hi fluffy. EBus is Very, VERY powerful and flexible system (Working with the Event Bus (EBus) System). But if you wanna work in classic way use that
AZ::Entity* entityPtr; // already created MyComponentClass* myComponentPtr = entityPtr->FindComponent<MyComponentClass>();
if (myComponentPtr )
{
myComponentPtr->Metod(Value);
}
But based on my experience in Lumberyard (AZ workflow not LY), I highly recommend use EBus system. Hope that help to you :)
For LY Componets look at LmbrCentral Gem. For Physics Look at AzFramework/Physics/PhysicsComponentBus.
Example for add impulse from your component to PhysicsComponent if all components created in one Entity.
#include "AzFramework/Physics/PhysicsComponentBus.h"
......
PhysicsComponentRequestBus::Event(GetEntityId(), &PhysicsComponentRequest::AddImpulse, AZ::Vector3 (0.0f, 0.0f, 50.0f));
ComponentBus by default using BusId as AZ::EntityId, and GetEntityId() returned owner EntityId.
You are amazing, thx!
Just for now I trying figure out with this Ebus stuff (https://docs.aws.amazon.com/en_us/lumberyard/latest/userguide/component-entity-system-pg-components-and-ebuses.html)
Let's say I made simple component called "JumperComponent" and implement for it EBus (JumperComponentBus) with one method "Jump". Now I planed made a Slice with : SphereMesh + PhysicComponent + and this my component (Jumper). So my question is: How to use Ebus to send message for Physic Component (same Slice with JumperComponent) and say to it "hey! you must jump up!" (add Impulse)
and lastly, where in documentation we can find all those Buses-implementations for various std components that shipped with LY from box? or we must just surfing sources of engine to find those ?
I tryed to send with helps EBus event for all JumpersComponents on level (currently have only one)
else if (azstricmp(actionString, "jumpers") == 0) // just test event polling {
//EBUS_EVENT_ID(GetEntityId(), JumperComponentBus, Jump);
EBUS_EVENT(JumperComponentBus, Jump);
}
else
<br>
but without any success( Is I'm right in suggestion that the "EBUS_EVENT(JumperComponentBus, Jump);" doing broadcast event polling for any component that implement "JumperComponentBus" with method "Jump"?
void JumperComponent::Jump()
{
AzFramework::PhysicsComponentRequestBus::Event(GetEntityId(), &AzFramework::PhysicsComponentRequestBus::Events::AddImpulse, AZ::Vector3(0.0f, 0.0f, 500.0f));
}
Yes you right if using EBUS_EVENT it will send to all JumperComponent in level.
p.s.
I think you forgot in your JumperComponent in Activating() add line
JumperComponentBus::Handler::BusConnect(GetEntityId());
and for Deactivate() in JumperComponent
JumperComponentBus::Handler::BusDisconnect();
But I was thinking that only component what implements some Ebus interface need to connect to it.
Thx I'll try to connect to JumperComponentBus from my own CameraComponent.
Yes you right, for your example. But Some times need create YourComponentNotificationBus, and that EBUS need connect to class which should listen events from component.
About "Thx I'll try to connect to JumperComponentBus from my own CameraComponent." I'm not sure I understood correctly, but in this case you need use JumperComponentBus::Handler::BusConnect(GetEntityId()); in your JumperComponent::Activate();
the Ebus-logic that I want to test it's fairly simple. My CameraComponent on keyH send Broadcast event for all JumperComponents on level, when Jumper got this event - it immidiately send event for only own entity with PhysicComponent and applying Impulse for whole entity.
Why when your CameraComponent on keyH not sending directly to specific JumperComponent ? Or am I missing something ?
oh my apologies, I just forgot connet my JumperComponent to it's own EBus hehe ) Now EBus-event Broadcasting from my CameraComponent work for one this Jumper. But actually Jumper even not jumping after all of this ) I think Impulse too small
I just talked about it :) I always forgot about it at first )))
Esta postagem está fechada: a adição de novas respostas, comentários e votos está desativada.
Conteúdo relevante
- AWS OFICIALAtualizada há um ano
- AWS OFICIALAtualizada há 2 anos
- AWS OFICIALAtualizada há 3 meses