+1
Answered

variable value is changing when i using get variable

irfan 2 years ago updated by Lazlo Bonin (Lead Developer) 2 years ago 3

i want list variable unchanged. So i did this.But when i run the graph it not only remove the value of "extra".But also "list'. 

but i don't want to change the value of "list".

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):
GOOD, I'M SATISFIED
Satisfaction mark by irfan 2 years ago
+1

yes here is the thing, and it is behaving properly. A list is a reference type, so when you assign list to extra, you aren't copying the values over to another list. You are actually saying "extra" is now the SAME EXACT list as "list". 

2 things you could do.

1. do a for each or for loop, and iterate through copying each value, but not the whole of the list itself.

2, the Ludiq cheat code. Has a method called CloneViaFakeSerialization. Where it does all the proper copying, treating the outcome as a brand new list you would assign extra as, instead of directly copying list.

After that, list and extra are not using the same list anymore. Essentially how you have it now, both lists are then the exact same instance, so changing any value after that effects both.


ye like  jason said first copy items from one list to another and then manipulate how you want change or remove