Scene Component doesn't update array values

If a scene compoment has an dictionary variable and is attached to an actor. The array values aren’t updated propery.

[Here’s a link][1] to the example project if someone wants to run it and check for themselves

The explanation is long, but please bare with it.

Scene Component example.

Just a simple SceneComponent with a single variable : Dictionary of StaticMeshes to Integer:

I have an Actor which takes the array values from the component and spawns meshes based on that

Spawn function is called in the construction script and begin play event :

Here’s where the issues begin.


Scenario1 : Actor blueprint has default values set for the component.

Overriding component values on an actor instance in a level does absolutely nothing in editor or in game!


Scenario 2: Actor blueprint has no default values.

Values are ignored on the actor instance in editor, but they read properly on BeginPlay, and work fine in game


This leaves me with two options:

  1. I can use only default values set in actor’s blueprint, which defeats the purpose of a variable.

  2. I must set values for each actor instance in a level : which defeats the purpose of a default value, and on top of that I don’t see how the meshes are placed in editor.

Neither of the two are viable, and if I don’t manage to sort this thing out, there’s no point in continuing the project, so help would be extremely appreciated

Okay thanks for the project and detailed images, it helps us understand the problem better.

  1. Dictionary has a set of meshes and an integer value, that denotes how many times it would spawn. For example Cube has 5 means it will spawn 5 cubes.?
  2. Now you tried to set the values in compile time as default values and it is not working?
  3. I think if you put a break point in the second image when you iterate through the dictionary, is the dictionary still having all the values? Did you set the values in the component after you attached it to the actor in the actor BP ?
  4. Have you tried passing in the dictionary by reference to the Spawner function?

If you still can’t get it to work.

Solution1:

  1. Create a struct ‘Couple’ that has “Keys and Values”, Cube | 5
  2. Create a Data table with those structs, say for Level 1, You create a Level1Datatable that has all the info you need, Cube 5, Sphere 6, Cylinder 8
  3. In the level blueprint, read those values from the data table and spawn them.

Solution2:

  1. If you still want this as a component that you can just attach as a plug and play, you can still write logic in the component to read the value from the data table and spawn them accordingly, that way its more pluggable across different games.

Also I dont have 4.19, if you have a 4.18 project I would probably find the solution.

Hey shrikky

Thanks for the reply. I’ve added 4.18 version of the test project to the gDrive folder

Here are the steps for testing the project if you want to give it a go


  1. Open My_Actor blueprint, select ArrayComponent and put any combination of a StaticMesh, integer value in TestDictionary variable

  2. Select TestActor placed in the level and try changing ArrayComponent-> TestDictionary values there and see what happens (after you update the values, click „Play“ too)

  3. Go back to My_Actor blueprint and remove all elements from ArrayComponent->TestDictionary

Repeat step 2)

Just to clarify a little more

You are correct that static mesh <–> integer combination denotes how many meshes of that type will be spawned

I have an actor with a component. That component has a Dictionary variable.
And in the actor’s blueprint I’ve set the default values for that dictionary.
But when I place the actor in a level and try to overwrite the values from the dictionary, it doesn’t work.

What’s in the actor blueprint is always used. Values that are set on the actor’s instance in a level are ignored.

EXCEPT if the actor’s blueprint doesn’t have a default value (empty array). In which case the new values are ignored in the editor, but get read properly during compile time – that’s why spawning the meshes in BeginPlay event works ok.

I tried creating a struct, but I run into the same issue. Because there will be more combinations of mesh<->int I would need an array of structures and the exact same issue happens.


Datatable won’t help me much I’m afraid either, because it’s a bit more complicated. I should have a lot of actors with this component all over my level, so I would need a lot of DataTables, or a single one with an key to denote wich component uses what rows. Would make my life very complicated compared to clicking on an actor and changing the values directly.

I solved it.I found another way

Step 1 : Make the dictionary private in the my_Component.

Step 2: Create a Function called SetDictionary That takes in a dictionary (Pass by reference enabled)

Step 3: Create a new dictionary in the actor class, pass it by reference into the components set dictionary function

Step 4: Make sure to add a condition check, if the incoming is dictionary length is greater than 0, then apply to the component dictionary, other wise don’t. This is important as this makes sure the default value that you set in the component works.

Make dictionary size 0 in the Actor values in the editor if you want it to use default values.

Thank you for the suggestion. I see what you did, and it’s a solid idea.

Might be able to work out something along these lines, but not sure if it’ll be a viable solution for the long run. Problem is the actor might have a few of these components in it, which means I would have to create a structure Mesh<->Int, then in the actor read the number of components, create an array of structures and pass the every structure to a matching component…

But for all that effort I might as well just carry the information in the Actor (rather than have a component, which was the whole point). In my project proper, things are much more complex and a component brings with it a lot of functionality. I honestly don’t know what issues might pop up further down the road with this apporach. I can already see I’ll probably need interfaces to make sure every actor has necessary functions and whatnot.

Thank you again for your effort and advice, but I’m very tentative about it all.

Whish Epic would acknowledge this as a bug, which it obviously is.

That way I’d at least have hope of it being fixed sometime in the future.

No problem ! Glad to help. I agree that it was more like a work around for short term. If its going to be an important component in your system, then we need a extendable solution.

I would definitely recommend Interfaces (contracts) + Components (Implementation) route. However the default value override seems to be a more of a bug.

Hello,

We’ve recently made a switch to a new bug reporting method using a more structured form. Please visit the link below for more details and report the issue using the new Bug Submission Form. Feel free to continue to use this thread for community discussion around the issue.

https://epicsupport.force.com/unrealengine/s/

Thanks