Announcement

Collapse
No announcement yet.

Casting to a newly created Actor... How to?

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

    Casting to a newly created Actor... How to?

    Hey,

    fairly new to BPs. I'm trying to make a class system in an RPG - note that the player will party up with NPCs and fight old-school RPg combat style. I wanted to keep it clean, so I made new actors called "Mage", "Rogue" etc, gave em stam, int, etc variables. Now I'm trying to access those variables from another BP but I have no idea how. I know I could put all the variables in the original character BP, but like I said, I wanted to keep it clean.

    What do I cast to? Is there some sort of variables library I can make and do it that way? No amount of googling has helped me here.

    Thanks in advance!

    #2
    Originally posted by Goldenguyz View Post
    What do I cast to? Is there some sort of variables library I can make and do it that way? No amount of googling has helped me here.
    Cast requires an object Input & Output on Left & Right side...
    An Object / Child / Member-access / Conversion must occur.
    Its not some magical node that creates objects from nothing.
    Its confusing as its a programming concept badly explained....
    Search through other 'Cast-To' past posts as that might help.

    First, you need to learn how-to structure Blueprints to communicate.
    Typically you need a shared Blueprint in the middle i.e. gamemode.
    Or use node Get-All-Actors-Of-Class (sparingly) to connect the two.
    Watch some basic tutorials and take apart sample projects to learn.
    BP uses OOP, that makes it harder to learn at first vs simple scripts.

    Last thing:
    Google hardly needs the advertising. Stop feeding the data monster!
    Last edited by UnrealEnterprise; 01-29-2020, 06:31 AM.

    Comment


      #3
      Your mage blueprint is a class, not an object. When you put it in a level or spawn it, you get an object.

      If you want to cast to it you need to specify which object you want to cast to. I guess, when you spawn "mage" you could promote it to a variable and pass that along to the player character blueprint. Then you can do whatever you want with it.
      Last edited by mlindborg; 11-09-2017, 08:49 PM.
      Character Customizer

      Comment


        #4
        Originally posted by franktech View Post

        Cast requires an object Input & Output on Left & Right side...
        An Object / Child / Member-access / Conversion must occur.
        Its not some magical node that creates objects from nothing.
        Its confusing as its a programming concept badly explained....
        Search through other 'Cast-To' past posts as that might help.

        First, you need to learn how-to structure Blueprints to communicate.
        Typically you need a shared Blueprint in the middle i.e. gamemode.
        Or use node Get-All-Actors-Of-Class (sparingly) to connect the two.
        Watch some basic tutorials and take apart sample projects to learn.
        BP uses OOP, that makes it harder to learn at first vs simple scripts.

        Last thing:
        Google hardly needs the advertising. Stop feeding the data monster!
        Consider switching to Startpage / Duckduckgo / Qwant or something!
        Thanks, I'll look into all this stuff. All I'm trying to do though is get the variables from that BP, surely there's an easier way or something?

        P.S. Nice try Comcast ;p

        If you want to cast to it you need to specify which object you want to cast to. I guess, when you spawn "mage" you could promote it to a variable and pass that along to the player character blueprint. Then you can do whatever you want with it.
        I'll try that thanks.

        Comment


          #5
          Originally posted by Goldenguyz View Post
          All I'm trying to do though is get the variables from that BP, surely there's an easier way or something?
          Just what mlindborg said.

          When you spawn Mage drag out that reference to a variable, and pass it into all the other blueprints that need it.
          That or stick a reference to Mage in Gamemode and use Get-Gamemode -> Mage to access it, in each BP etc.
          But best to plan this on paper (which BP's need access to others), otherwise the code becomes unmaintainable.

          Comment

          Working...
          X