Announcement

Collapse
No announcement yet.

Proper Separation of Logic When Casting?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Proper Separation of Logic When Casting?

    Hi, I am new to UE4. I've been using it for about a week now.

    I would like to get the community's opinion on the separation of blueprint logic with respect to casting and blueprint to blueprint communication. The UE4 docs on blueprint communication suggest using casting in the following scenario

    https://docs.unrealengine.com/latest...age/index.html
    You have a character interact with an Actor in your level and in turn causes a change to the character in some way.
    Player picks up a health pack in the level, restoring health in the player character.
    Enemy walks in snow or mud, causing their movement speed to slow down.


    The scenario is as follows from the UE4 document on Casting
    https://docs.unrealengine.com/latest...ing/index.html
    In this example we allow the player to shoot an object, making it smaller each time it is hit. Each time the object is hit, it also notifies the Character Blueprint and increases the player's movement speed.

    The document describes adding an event to the bullet blueprint and casting to the cube and player to effect a change in the objects. The cube is transformed and reduced in size. The Player receives an increase in speed. This is all done inside the bullet blueprint. I found it strange that they would embed this logic in the bullet blueprint. This seems like a poor design to me. (Question 1) Would it be better for each component to specify what should be done when hit by a bullet? If not it seems like the bullet blueprint hit logic would become unmanageable as you create a large number of object types with different behavior. Or maybe it would be better to use an interface.

    Also consider a scenario with a blueprint class derived from Actor called Car and it is composed of child component actors such as the wheels and frame. (Question 2) If the bullet hits the wheel I believe the two components in the hit event will be the wheel and bullet. Should the wheel cast to the parent blueprint to adjust a car wide effect in addition to the specialized effect within the wheel?

    Thanks for your input.

    #2
    Interfaces provide an appropriate means to affect changes in objects that have no relationship to one another.

    As a rule of thumb i always go by "Objects should manage themselves". In your example you are correct in saying that it is more appropriate for the Cube to decide what to do when it is hit by a Bullet, not the Bullet deciding what to do for the Cube. The only thing that they should end up sharing at that instance would be the Event Hit.
    Im an Moderator on UnrealSlackers Discord! Which is a Community driven group of likeminded people here to discuss UE4! Join UnrealSlackers on Discord!

    Comment

    Working...
    X