Announcement

Collapse
No announcement yet.

Casting to an actor thats not the player or player character

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

    Casting to an actor thats not the player or player character

    What im trying to do, is when a button is pressed, the button tells the door to open if the button link and door link are the same int (https://cdn.discordapp.com/attachmen...41/unknown.png https://cdn.discordapp.com/attachmen...65/unknown.png) although the casts are not working, and i can't figure out what needs to be plugged into the casts object pin. (https://cdn.discordapp.com/attachmen...36/unknown.png https://cdn.discordapp.com/attachmen...54/unknown.png) Im trying to do it with the links so i am able to get multiple buttons and doors on one level, without 1 button opening all doors, and without needing to duplicate them.

    #2
    You cant cast directly from an actor to another actor, which are separate entities in the level. You will need to do the logic around a common ground they both share-, level blueprint, player character, or gamemode. The door actor doesnt know that the button exists, this is why you cannot make references of each otheir either.

    You could use the door actor to "spawn actor" "button" to the level when the game starts as his child object, and then reference to the button from the door actor, but I would recommend using just the main blueprints to control this. Otherwise you will be in a chaos figuring out which blueprint controls what, when levels get more complicated.

    Since they are objects on the level, the most logical place to do casting and handling the operations would be the Level Blueprint. From there you dont even need to use cast nodes, but simply by drag the objects fom the World Outliner into the Level Blueprint. Then you can read/write variables withing the 2 using the level blueprint.
    Last edited by Manatee; 06-28-2018, 12:19 PM.

    Comment


      #3
      I would recommend Direct Communication https://docs.unrealengine.com/en-us/...BlueprintComms
      1. Door_Blueprint
        1. Create a Door_Blueprint and place it in the map
        2. Create an Event named OpenDoor
      2. Button_Blueprint
        1. Create a Button_Blueprint and place it in the map
        2. Create a Door_Blueprint (Object reference) variable and mark this variable as "Instance editable"
        3. Select the Button_Blueprint in the level and assign the Door_Blueprint instance you placed in the map (step 1.1) to the variable
        4. In the EventGraph get the Door_Blueprint variable and use it to call OpenDoor when the button is pressed eg.

      If the button needs to open several doors simply make the variable into an array and use a foreach loop when calling OpenDoor

      You can place as many instances of buttons and doors in the map as you like. Link the button instance to the door instance as described in step 2.3
      Last edited by GarnerP57; 06-28-2018, 04:12 PM.

      Comment


        #4
        You need to get a ref to the object you want to access. You can either use Collision components or traces https://docs.unrealengine.com/en-us/...To/UseRaycasts.
        Either will give you information of the object it hits so you can cast to it and access it's parts.

        Here is a tutorial:
        https://www.youtube.com/watch?v=DTNO4kULts4
        Check out my itch.io page, I'm really excited about it.
        https://kinos141.itch.io/

        Please check out my AI package: Action AI System Feat. Stealth
        https://www.unrealengine.com/marketp...m-feat-stealth
        or get it from itch
        https://kinos141.itch.io/action-ai-system-feat-stealth

        Comment

        Working...
        X