0
Not a Bug

Strange behaviour, clearing and seting Dictionaries variables BOLT1

Duna Games 3 weeks ago updated 3 weeks ago 6 1 duplicate

I'd done a post about it for Bolt2 but testing the same thing on Bolt1 gave the same error.
When clearing a dictionarie, and setting it right after, the dictionarie and the source gets empty, but only after a second interaction, minimal reproduction steps are below:

See how it works with only one output port from Sequence connected:

Thats it, thanks.

Bolt Version:
Bolt 1.4.9
Unity Version:
2019.3.0b11
Platform(s):
Windows
Scripting Backend:
Mono
.NET Version (API Compatibility Level):
.NET 4.x
GOOD, I'M SATISFIED

Great as always!

Satisfaction mark by Duna Games 3 weeks ago

Duplicates 1

Found something about it, if we wait one frame, the Clear will do its job,... it seems the Clear unit only take effect the frame after.

Here the test I did:

https://imgur.com/iMwPVAV

The console log without using next frame corroutine:



And using it, all normal:

Need More Information

Hi Duna Games,

I'm having a hard time following what you're trying to do here, I need more information.

  • Are A and B pointing to two different dictionaries of the same type? (Dictionary<int, List<string>>)
  • After the first iteration, you're setting B to A. Are you aware that this doesn't copy the dictionaries, but instead changes the reference to the dictionary? In other words, after this Set Variable, both A and B point to the same dictionary object, not two different objects.
  • Therefore, if you clear B after the first iteration (including the Set Variable), you also clear A, because they're the same object.

Are you sure this is a bug? Honestly I'm not sure what you're trying to accomplish and I would appreciate a simpler example.

+1

Thanks for the information, I was not aware that set does not copy the dictionaries, so, this is not a bug, sorry.

Besides that, I didn't find info about this different behavior compared with other variables, were may I find more about it?

Not a Bug

Glad to have cleared that up!

Cloning data structures is a complex operation in all programming languages. If you want a true clone, the simplest way is to iterate on the first dictionary and recreate a new one by adding each key individually. Note that lists behave in the same way: if you just pass the list value from the first to the second, you're not copying the list, you're just passing a reference to it.

Thanks again, would be amazing to have this in the documentation!