Download

Please clarify behavior of variables in blueprints

On my dedicated server, in my GameMode class, I have defined an map. Let’s call it BigMap.

In an actor, I want to access BigMap and add a bunch of entries to it. Let’s say 50.

To me, there are a few ways to do this:

  1. Access GameMode, from that access BigMap, from that do a foreach adding the items directly to BigMap. I would expect this to work as expected.

  2. Access GameMode, from that access BigMap. Set a local Map variable to equal BigMap. Add the 50 items to the local map. I would expect this to work the same, they items get added to BigMap.

#2 doesn’t seem to work. It appears that doing a SET isn’t setting a reference to BigMap, it COPIES big map to local map. The items are only added to the local map. BigMap stays empty.

Can I get confirmation that this is working as expected?
More importantly…is there documentation anywhere that goes over this behavior, and the behavior of blueprint gotchas in general?

Only objects are passed/assigned by reference. Everything else, including arrays, maps and sets, are always copied by default. However, you can mark function inputs as “by ref”, which will make the pin contain a reference instead of a copy. Reference pins are diamond shaped instead of circle shaped.

Thank you, I got some other clarification in another thread.
I’m surprised arrays, maps and sets are not passed by reference also, I would expect most people to use these to store data and they could be pretty heavy to pass around a lot. Hopefully Epic will change this, until then…I suppose I could create an object that HAS these and pass that around.