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

posta 5 anni fa183 visualizzazioni
16 Risposte
0
Risposta accettata

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

con risposta 5 anni fa
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.

con risposta 5 anni fa
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 ?

con risposta 5 anni fa
0

Thx! exactly what I'm need)

con risposta 5 anni fa
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"?

con risposta 5 anni fa
0
	void JumperComponent::Jump()
{
AzFramework::PhysicsComponentRequestBus::Event(GetEntityId(), &AzFramework::PhysicsComponentRequestBus::Events::AddImpulse, AZ::Vector3(0.0f, 0.0f, 500.0f));
}

con risposta 5 anni fa
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();

con risposta 5 anni fa
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.

con risposta 5 anni fa
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();

con risposta 5 anni fa
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.

con risposta 5 anni fa
0

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

con risposta 5 anni fa
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

con risposta 5 anni fa
0

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

con risposta 5 anni fa
0

gif

10 character

con risposta 5 anni fa
0

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

con risposta 5 anni fa
0

Thanks to you)

con risposta 5 anni fa

Questo post è chiuso: l'aggiunta di nuove risposte, commenti e voti è disabilitata.