Announcement

Collapse
No announcement yet.

How do I Set Actor Variable from Array...

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

    How do I Set Actor Variable from Array...

    Hi there,

    Happy New Year to you all and wishing you a great year ahead...

    I have spawned 10 Actors into the scene and they are Ball meshes and each actor has a variable... Each actor has a variable called CurrentDistance1, CurrentDistance2
    , CurrentDistance3, CurrentDistance4, CurrentDistance5, CurrentDistance6, CurrentDistance7, CurrentDistance8, CurrentDistance9, CurrentDistance10.. Its a Spline thing... LOL.. So each ball actor is like ball1, ball2, ball3, ball4, ball5, ball6, ball7, ball8, ball9, ball10.. So just wanted to name the variables with numbers for reference.. Not to say I would have too..

    I have a Array called Spawned Balls which contains these 10 actors.. As you can see below.. I have a ForLoop that cycles through each one and I GET them from the Spawned Balls Array...

    What I want to do is set the variable for CurrentDistance[NUM] to another value for each Ball Actor in the Array... I just have no idea how I can do that... I have searched Youtube and Google and there is not much about it, unless I have looked in the wrong places LOL...

    In the screenshot below I am just using a Event BeginPlay to keep things simple for this Question... Its actually in a very big blueprint I am working on and just don't want to complex things... If anyone could help me on this that would be great, I have spent some time trying to work this out for myself but with no avail..

    If I have to remove the numbers from the variables to make it work that is fine...
    Any help would be great once more

    I believe this could help others also with this same problem... I have tried to keep this simple.. So others could learn from the answers which are given to this problem..

    Click image for larger version  Name:	BallsArray.jpg Views:	1 Size:	38.4 KB ID:	1568509
    Last edited by ZeroVector; 01-04-2019, 02:04 PM.

    #2
    the SpawnedBalls array - that is an Array of "Actor"? you probably have to cast the result from the get as the Ball Blueprint so it can see the variable? also make sure that variable is public
    Every day I beat my own previous record for the number of days I've stayed alive!

    Comment


      #3
      GeeksGoneBad is right, unreal doesn't really know what the actor is and what variables it has in it, so you have to do a Cast ,witch is basically a check to see if the actor is actually a ball or not.

      Here is some documentation on how to do that:

      https://docs.unrealengine.com/en-us/...uide/CastNodes

      One more thing, how are you setting the variables from the Spawned Balls array? Are you adding them to the array as you spawn them? Or by using get all actors of class?

      If you use get all actors of class, and you select ball class, promote the array to a variable, then you can modify their distance value without needing to cast, because you are already telling unreal to search for the ball class.

      Hope that makes sense, casting took a while for me to wrap my head around it.



      Comment

      Working...
      X