Workarounds for referencing TArray of pointers to UStruct
I have a situation where I have a "graph" of different nodes contained in a
All 3 of these are stored in 3 different
The logical way to access the first vertex of a
As it is right now, neighboring structures are actually being referred to by integers (which correspond to the index of that structure in its respective array). Here's that above example, where I try to fetch the first vertex of a
As you can see, about 0% of that was intuitive. It doesn't make sense that accessing the first element in the vertices array would return an integer. It doesn't make sense that getting a vertex by index would return a copy and not a reference. It doesn't make sense that you'd need to "manually" update the graph after you make changes to something.
I'm not sure exactly what a good workaround would be. I'd like to leave as much exposed to Blueprints as possible. I've been trying to use
Any ideas? Or will this continue to just be super-confusing?
asked Jun 02 '17 at 01:59 AM in C++ Programming
This is a bit cludgy, and I'm not sure that it will actually streamline anything for you; but this might help.
You say, "It doesn't make sense that getting a vertex by index would return a copy and not a reference." and I'm not sure why you're choosing not to return by reference. I may have missed something in your explanation, but as far as I know that can be done in the situation you're describing.
You also say, "I can't call any functions declared within the UStruct within Blueprints, so I haven't really written any functions for them."
And this is correct, to a point. However, you can expose methods within structs to being called within a Blueprint by creating an intermediary library of static methods.
For use in C++, you can build your structs as you would without regard to BP, and use pointers to neighbors etc. You can build methods within your structs to perform the graph updates automatically; and you can build accessor methods that traverse the internal pointer chain to get the desired data.
Once you have that complete, you can build a BP Static Library of methods that call the methods within your structs for you.
A simple example might make this more clear. Let's say you have a struct:
Normally, the internal methods and the HiddenLocation variable would be inaccessible from BP. But if we create a UBlueprintFunctionLibrary of static methods, we can access and modify the values:
Follow this question
Once you sign in you will be able to subscribe for any updates here