I've got some more clarification on another thread, and this person stated that in general, objects actors and such are passed by reference, even when referencing them in another object. Maps, arrays, and sets are NOT when you are just referencing them as a property on another object, instead they are copied. This is surprising to me, it seems very ineffecient as these types are meant to store data, and often lots of it.
Regardless, it may be better for me to have a dedicated Object in GameMode, which is responsible for storing these types, and I then pass that around.
Again, the issue is you don't always get these passed in via an input in a function or macro, sometimes you just access them as a variable in another object.
I do wish Epic could document/clarify this.
Announcement
Collapse
No announcement yet.
Blueprint rules for references to other objects
Collapse
X
-
UnrealEnterprise repliedOriginally posted by Strombonni View PostOk, I thought that might be what Bruno was talking about. Sadly, in this case it's not a function or macro input.
Leave a comment:
-
Strombonni repliedOk, I thought that might be what Bruno was talking about. Sadly, in this case it's not a function or macro input.
Leave a comment:
-
UnrealEnterprise repliedOriginally posted by Strombonni View Post<<<There's a " pass by reference" checkbox in there>>>. I guess I'm blind...I don't see that on any of the nodes. I have a node to get the game mode, a node off of THAT to access its TradeSkills property, and a node from there to set a local variable to the GameMode.Tradeskills property. On none of them to do I see a pass by reference.
In a Macro or Function definition, its part of the Details-pane 'Inputs'.
It may be hidden, so click on the 'expand icon' to view the dropdown.
Then you should see a Tickbox marked 'Pass-By-Reference' etc etc...
Leave a comment:
-
Strombonni replied
Originally posted by BrUnO XaVIeR View PostThere's a " pass by reference" checkbox in there.
I guess I'm blind...I don't see that on any of the nodes. I have a node to get the game mode, a node off of THAT to access its TradeSkills property, and a node from there to set a local variable to the GameMode.Tradeskills property. On none of them to do I see a pass by reference.
Originally posted by GarnerP57 View PostNobody is stopping you from making it as efficient as possible by leveraging C++. Blueprint can do a lot of things but it is a shell of what C++ is so it has many limitations still.
You mention that you use GameMode to make sure it happens on the server. There is many ways you can ensure things happen on the server from any actor that live on the server. The "IsServer" function that returns a bool is one of them. "HasAuthority" is the most common way of asking a replicated actor if it is server-side or client-side.
But, are you seriously saying that accessing a MAP object variable defined in the GameMode, and storing a reference (not a complete copy) it in the calling blueprint's local variables is out of the question, and I need to use C++ instead? I promise you, the guys in the Unity forums would have a field day with THAT, and I personally don't consider it reasonable, especially for a potentially data heavy object like a map. A value type, sure. I would expect a copy. I mean...it's fine, I can work around it, but still I find it hard to believe that Blueprints would behave this way.
Also, I didn't say I use GameMode to make sure it happens on the server, I think you misunderstood what I said. What I said was, I'm using the GameMode to store the map contents because I know this is happening on the server. And I'm pretty sure the GameMode is a recommended place to store this kind of data that I want to persist in memory, or at least from what I've read.
Leave a comment:
-
GarnerP57 repliedNobody is stopping you from making it as efficient as possible by leveraging C++. Blueprint can do a lot of things but it is a shell of what C++ is so it has many limitations still.
You mention that you use GameMode to make sure it happens on the server. There is many ways you can ensure things happen on the server from any actor that live on the server. The "IsServer" function that returns a bool is one of them. "HasAuthority" is the most common way of asking a replicated actor if it is server-side or client-side.
Leave a comment:
-
Strombonni repliedWell, this just blows my mind. I'm from the C# world, where reference types like arrays and other objects are never copied like this, you get a pointer/reference to the original object. I mean..what if the map is huge, that's incredibly inefficient.
I gotta get confirmation on this.
As far changing the gamemode...well, yes, but every time I wanted to reference it I'd have to get a reference to my gamemode, then from that access the tradeskills map. It's...clunky.
Oh, I'm using GameMode because this is all happening on the dedicated server.
Leave a comment:
-
SkeetonYu repliedOriginally posted by Strombonni View PostI would expect local variables to be removed after the function is done, it's a scope thing.
But, let's say I have an array defined in my GameMode. I have a local array, that I set to equal the gamemode array.
I would expect this to basically be a pointer to the array, and if I add elements to the local array they should actually be added to the GameMode array.
Unless...blueprint local variables are always COPIES of the gamemode array, as if they were value types.
In this case, is it a pointer to the original array, or a copy? If it's the latter, color me shocked.
Any reason you can't just change the Gamemode All trade?
Leave a comment:
-
IronicParadox repliedOriginally posted by Strombonni View PostBut, let's say I have an array defined in my GameMode. I have a local array, that I set to equal the gamemode array.
I would expect this to basically be a pointer to the array, and if I add elements to the local array they should actually be added to the GameMode array.
You would need the following workflow to make that work:
GI has some populated array in it
BP has some function that gets a reference to the GI, reads it's array and set's a variable, within the BP, to equal the GI's array
BP does some stuff to that copy of the array and now wants to push the updated information back to the GI
Right click in BP, get current game instance, cast to the custom game instance that you made(the name will match so make sure you name it something you will recognize)
From there, you can access the GI's variables and set that array equal to your array within the BPLast edited by IronicParadox; 04-30-2018, 09:19 PM.
Leave a comment:
-
Strombonni repliedI would expect local variables to be removed after the function is done, it's a scope thing.
But, let's say I have an array defined in my GameMode. I have a local array, that I set to equal the gamemode array.
I would expect this to basically be a pointer to the array, and if I add elements to the local array they should actually be added to the GameMode array.
Unless...blueprint local variables are always COPIES of the gamemode array, as if they were value types.
In this case, is it a pointer to the original array, or a copy? If it's the latter, color me shocked.
Leave a comment:
-
SkeetonYu repliedI might be misunderstanding what your trying to do but local variables deletes itself once the function is done. It doesn't retain any data.
Also if the variables can hook up then it works. Unless it shows an error. The other thing since you said its being called on initialization is that the All trade variable is being set before the game mode initialize. So it'll return as null. Just add a delay 0.1 or something.
If you already check these just ignore me.
Leave a comment:
-
Strombonni started a topic Blueprint rules for references to other objectsBlueprint rules for references to other objects
TLDR: Local reference types don't seem to actually keep references.
In my GameMode class, I have a Map, TradeSkills.
I also have a function library my other blueprints use for handling tradeskills. In one of the functions, I needed to operate on the GameMode TradeSkills map a lot, so I set a local variable to reference it and work off of the local map.
At this point, I would expect if I add entries to the local map, it would actually add it to the tradeskills map. This doesn't seem to be happening.
This function is being called from the GameMode itself (for initialization), so I know it's happening on the server.
Are there not two types of variables in blueprints, reference types and value types? I would expect a MAP to be a reference type. Or, is there some aspect of GameMode I am missing?
Tags: None
Leave a comment: