How you guys made communication between same entity's components or Slice components?

0

I saw something about EBus usage in code, so I guess there no more way to doing it in more classic way with helps direct calling - m_entity->GetComponent<someComponent>->Method1(value) ?

feita há 5 anos183 visualizações
16 Respostas
0
Resposta aceita

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 :)

respondido há 5 anos
0

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.

respondido há 5 anos
0

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 ?

respondido há 5 anos
0

Thx! exactly what I'm need)

respondido há 5 anos
0

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"?

respondido há 5 anos
0
	void JumperComponent::Jump()
{
AzFramework::PhysicsComponentRequestBus::Event(GetEntityId(), &AzFramework::PhysicsComponentRequestBus::Events::AddImpulse, AZ::Vector3(0.0f, 0.0f, 500.0f));
}

respondido há 5 anos
0

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

respondido há 5 anos
0

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.

respondido há 5 anos
0

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

respondido há 5 anos
0

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.

respondido há 5 anos
0

Why when your CameraComponent on keyH not sending directly to specific JumperComponent ? Or am I missing something ?

respondido há 5 anos
0

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

respondido há 5 anos
0

I just talked about it :) I always forgot about it at first )))

respondido há 5 anos
0

gif

10 character

respondido há 5 anos
0

Super !!!! I'm glad you did it fluffy :)

respondido há 5 anos
0

Thanks to you)

respondido há 5 anos

Esta postagem está fechada: a adição de novas respostas, comentários e votos está desativada.