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

asked 5 years ago179 views
16 Answers
0
Accepted Answer

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

answered 5 years ago
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.

answered 5 years ago
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 ?

answered 5 years ago
0

Thx! exactly what I'm need)

answered 5 years ago
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"?

answered 5 years ago
0
	void JumperComponent::Jump()
{
AzFramework::PhysicsComponentRequestBus::Event(GetEntityId(), &AzFramework::PhysicsComponentRequestBus::Events::AddImpulse, AZ::Vector3(0.0f, 0.0f, 500.0f));
}

answered 5 years ago
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();

answered 5 years ago
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.

answered 5 years ago
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();

answered 5 years ago
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.

answered 5 years ago
0

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

answered 5 years ago
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

answered 5 years ago
0

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

answered 5 years ago
0

gif

10 character

answered 5 years ago
0

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

answered 5 years ago
0

Thanks to you)

answered 5 years ago

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