Announcement

Collapse
No announcement yet.

Blueprint "Array Get by Reference", and edit struct elements directly

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Originally posted by Raildex_ View Post
    Still there's no sign that someone is working on this.

    https://forums.unrealengine.com/show...rk-with-Arrays
    Actually there is. I've mentioned an issue ticket in your thread and status was changed to "Not reproducible in 4.13". So now the only thing we can do is to wait for 4.13 to test it
    SuperGrid: Marketplace Page | Feedback Thread | Demo | Website
    Level design and prototyping for newbies

    Comment


      #17
      [MENTION=74042]CleanCut[/MENTION] UE-18616 was not added to the Public Jira site because it was a duplicate of other similar issues: UE-20424, UE-6451 and UE-24080

      Thanks!
      Twitter @UnrealSamantha
      Mobile Development Troubleshooting Guide | Package and Deployment Troubleshooting | How do I report a bug?
      Call me to a thread by posting this: [MENTION]Samantha Sutton[/MENTION]

      Comment


        #18
        Originally posted by zeOrb View Post
        Actually there is. I've mentioned an issue ticket in your thread and status was changed to "Not reproducible in 4.13". So now the only thing we can do is to wait for 4.13 to test it
        Well I just reproduced this issue in 4.13 so I hope it is still active

        The various reports Samantha mentions above should help hopefully

        Great job on starting this thread [MENTION=346351]Zhi Khang Shao[/MENTION]!

        ~~~

        C++ Solution

        An easy way to work around this if you have C++ powers and dont want to re-write a lot of code structure, is simply something like this:

        I tried to think of a Victory Plugin generic solution for BP-only users, but I know well the complexity of arrays in Blueprints, under the hood. It may require engine modification

        Code:
        UFUNCTION(BlueprintCallable,Category="Your Class")
        void SetBeatParam(int32 Index, FString Param, float Value);
        
        void AYourClass::SetBeatParam(int32 Index, FString Param, float Value)
        { 
        	if(!Metronome_Beats.IsValidIndex(Index)) 
        	{
        		VSCREENMSGF("Array access out of bounds!", Index);
        		return;
        	}
        	 
        	if(Param == "Enabled")
        	{
        		Metronome_Beats[Index].Enabled = (Value > 0) ? true : false;
        		return;
        	}
        	if(Param == "Channel")
        	{
        		Metronome_Beats[Index].Channel = Value;
        		return;
        	}
        	if(Param == "Pitch")
        	{
        		Metronome_Beats[Index].Pitch = Value;
        		return;
        	}
        	 
        	if(Param == "Velocity")
        	{
        		Metronome_Beats[Index].Velocity = Value;
        		return;
        	}
        	 
        	VSCREENMSG2("Unknown param!", Param);
        }

        It's subject to spelling errors but if you do some output like I do at the bottom you can catch spelling errors easy



        Rama
        Last edited by Rama; 09-28-2016, 08:46 PM.
        100+ UE4 C++ Tutorials on the UE4 Code Wiki, including UE4 Multi-Threading!

        UE4 Marketplace: Melee Weapon Plugin & Compressed Binary Save System Plugin | Rama's C++ AI Jumping Videos | Vertex Snap Editor Plugin

        Visit www.ue4code.com to see lots of videos about my C++ Creations! ♥ Rama

        Comment


          #19
          Originally posted by Rama View Post
          Well I just reproduced this issue in 4.13 so I hope it is still active
          I found that Break struct seems to return a ref but Set node seems to return a copy, (in 4.15.1)
          So, if we use a local variable as a cache (Temp attackable targets in sample), it's a copy.

          By the way, tooltip of Get node seems wrong (if it returns a ref).
          It says "a copy".
          And it lacks what will happen if index is not valid.
          (No error/log occurs but the values set to the struct member arrays seems to be ignored. This also be a possible bug.)

          Comment


            #20
            > No error/log occurs but the values set to the struct member arrays seems to be ignored.
            Correction.
            No error/log occurs when values are set to the struct member / member arrays (as if a struct exists),
            but original array of structs which is connected to Get node input pin will not changed (as the struct Get node returned is not contained in the original array of structs).

            Thanks.

            Comment


              #21
              Originally posted by Dev.TMG View Post
              > No error/log occurs but the values set to the struct member arrays seems to be ignored.
              Correction.
              No error/log occurs when values are set to the struct member / member arrays (as if a struct exists),
              but original array of structs which is connected to Get node input pin will not changed (as the struct Get node returned is not contained in the original array of structs).

              Thanks.
              What's the questions here? Could you post the setup that's giving you the headache? Admittedly, structs are a tad fiddly.

              Comment


                #22
                If Get returns a reference, Set also treats params as refeence is better.. I think. (Get is for getting a element from arrays, but we need some Set function to store the ref Get returns.)

                UE-24080
                https://issues.unrealengine.com/issue/UE-24080
                Improve Get Array Item to return by-ref instead of by-value

                >And it lacks what will happen if index is not valid.
                This part is my mis-understanding of Resize node etc behavior, sorry.
                My headache was
                1.Resize an array of struct which contain arrays as member < I thought this does not add elements.(as step 3 seems not work.)
                2.Get an element from the array < Can get. Can set values to arrays inside the struct after resize them.
                3.Try to use the struct in another place (Get from array of struct). < Seems not exist. This is a mislead point.

                Part of my troubles maybe depends on UE-6451.

                https://issues.unrealengine.com/issue/UE-6451
                Set Members in Struct node doesn't work if the Struct is contained within an Array
                (will be fixed in 4.16)

                Comment


                  #23
                  Originally posted by Dev.TMG View Post
                  If Get returns a reference, Set also treats params as refeence is better.. I think. (Get is for getting a element from arrays, but we need some Set function to store the ref Get returns.)
                  Not sure if I follow, can you show us an example of where you have trouble setting something?

                  Originally posted by Dev.TMG View Post
                  Part of my troubles maybe depends on UE-6451.

                  https://issues.unrealengine.com/issue/UE-6451
                  Set Members in Struct node doesn't work if the Struct is contained within an Array
                  (will be fixed in 4.16)
                  This already works fine if you use SetMembersInStruct node.

                  Perhaps you'd want to start a new thread with a pertinent example.

                  Comment


                    #24
                    >Set also treats params as refeence is better
                    Originally posted by Everynone View Post
                    Not sure if I follow, can you show us an example of where you have trouble setting something?
                    Maybe having a new thread is better but
                    the problem is that we tend to think Set also treats arrays as refs if the input is a ref.
                    (Set converts a ref to a copy, though.)

                    In 1st image of Zhi Kang Shao's post, "Temp Attackable Target" is a copy of "Enemies Within Attack Range",
                    so any changes to Temp Attackable Target does not affect Enemies Within Attack Range,
                    and needs to write it back with Set Array Elem.

                    What we want is that changes to Temp Attackable Target also changes original array (Enemies Within Attack Range).

                    Comment


                      #25
                      Please forgive a noob barging in, but i have strange dilemma.
                      I am following older tutorial on Youtube and in the version shown there there is just one 'Get' function. I am using 4.16 where i have two options (gasp). Which one should i choose to match the functionality of the tutorial, or older UE versions - 'Get' (a copy) or (a ref)?
                      Thanks.

                      Comment


                        #26
                        The distinction likely doesn't matter if you don't know which to use.

                        Basically, if you want to make changes to the variable, you'll need a reference. A reference points to the address of the original variable, which means that any changes to it are done to the original variable.
                        If you just want the variable in order to look at its content or store some temporary calculations inside of it, a copy is perfectly viable. A copy stores a copy of the value of a variable, as the name would imply. Make changes to it and the changes will only affect the copy, not the original variable.
                        Read up on pointers if you want to know more about the differences.
                        If you are using an old tutorial, it most likely works under the assumption that references are not possible. Meaning that the code will be intended for copied values anyway.

                        tl;dr
                        If the tutorial is that old, go with the copy.

                        Comment

                        Working...
                        X