Announcement

Collapse
No announcement yet.

Can not access custom event of dynamic object stored in an array.

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

    Can not access custom event of dynamic object stored in an array.

    Hi. I am using UE4.16.3.
    I would like to ask for a help how to access my custom event of dynamic objects placed in an array.
    I have spent quite a lot of time to get it work but I can not find the right solution.

    I am following this tutorial (Fun with Blueprints : Spawning Dynamic Objects): https://www.youtube.com/watch?v=9-7SmkasS_A
    I like a lot solution showed there but it was created in older version of the UE.
    Everything is working for me to the moment when I try to access my custom event of dynamic object stored in the array. (Video time: 25m19').

    Generally there are used two main blueprints for it:
    1. DynamicCow - used as an object dynamicaly spawn and stored in the array.
    The DynamicCow blueprint has custom event "DestroyThisToyCow" and the event is used in the Event Graph of this blueprint.

    2. SpawnVolume - the blueprint, in the Event Graph, spawns the "DynamicCow" objects, stores them in the array and
    at the end iterates by all "DynamicCow" objects stored in the array calling on each "DestroyThisToyCow" custom event.

    The video is showing available option to choose/use "Call Function For Each->Destroy This Toy Cow".
    In the current engine version I don't see that option.
    I try to use "Array->ForEachLoop" but it doesn't give me the access to my custom event created for "Dynamic Cow".
    I try to cast the object returned by "ForEachLoop".
    One approach - casting into "Class", the second into "Reference" (Like on the screenshots).
    In my case the "DynamicCow" blueprint I have named "MyDynamicObject"
    and custom event "DynamicCow->Destroy This Toy Cow" I have named "MyDynamicObject->Destroy This Dynamic Object".
    In both casting situations I am getting error. I have try to solve the error but can not get around it.
    The approach I would like to archive is to work directly on the objects placed in the array, not on a new copies.
    Could someone please help me to solve the problem?

    Click image for larger version

Name:	ForEachWithCastingToClass.png
Views:	1
Size:	362.6 KB
ID:	1226206
    Click image for larger version

Name:	ForEachWithCastingToReference.png
Views:	1
Size:	374.8 KB
ID:	1226209
    Attached Files

    #2
    You are storing object class rather than object instance in your SpawnedDynamicObject array. Have a look at 15:30
    Note the node colour: purple = class; blue = object reference.

    Comment


      #3
      Yes, you are right Everyone.
      It looks like I have found solution for my problem.
      Instead of creating the array of classes like suggests the tutorial I created the array of references to dynamically spawned objects
      and I can use "ForEachLoop" instance to get access to my custom event. Done

      Click image for larger version

Name:	203710-usingforeachlooponarrayofreferences.png
Views:	1
Size:	503.4 KB
ID:	1132112

      Comment

      Working...
      X