0
\$\begingroup\$

I was following a tutorial on using GameInstance. Where the guy in the video would teach how to choose the color of the ship by clicking a button on a level (x), so as to affect the ship on another level (y).

LINK OF VIDEO (in portuguese):

https://www.youtube.com/watch?v=kTiCjPHMJXI&list=PLnwVxZ2WVVpl1sOPaEzK--4fXzq2ZQvE-&index=42

LEVEL X:

enter image description here

CODE OF BLUEPRINT MENU OF LEVEL X (when buttons are clicked):

enter image description here

This code is associated with an enumeration with these three colors (red, green and blue).

My problem appears when I set the target in the function (Set Scalar Parameter Value), it only appears these options for me:

enter image description here

Much like the problem this person had:

https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/90544-material-parameter-collection-reference-variable

In the video it can give a "get" in the variable, which later (apparently) I discovered to be a reference to the object:

enter image description here

I made the "discovery" based on the sign (blue circle):

enter image description here

I did tests with the "blue circles" type variables, but the ones I did did not work.

enter image description here

https://answers.unrealengine.com/questions/169593/how-to-properly-set-vector-parameter-value.html

I would like to know what I have to do so that the referral is done correctly.

Another link that I researched, but that did not help me much.


EDIT 1 (attempt based on Stephen's answer)

**I created a material instance and put it right after the Event Begin Play (I found 2 options, so I did the test with both).

Available Options:

enter image description here

Blueprint:

enter image description here

I defined them as editable, just as I was instructed.

But even so, I could not:

enter image description here

I could not connect the nodes. Warning "Material Intance Dynamic Object Reference is not compatible with Material Parameter Collection Object Reference" is displayed.

\$\endgroup\$
0
\$\begingroup\$

(Apologies, I'm at work so can't provide pictures, hope my descriptions are good enough but I'll try to edit later)

The reference you are referring to isn't just a random reference, you have to tell the editor what you're trying to change the material instance of. In my experience, this would be a static mesh of some sort.

At Begin Play in your ship blueprint, you need to create that Material Instance. From the Return Value of this, right click and choose Promote to Variable. Name it and make it editable.

In the blueprint which is choosing the colour, at Begin Play, get player character (or pawn), pull the right pin and choose CastTo[YourPlayerBlueprint] then from the result of this, promote it to a variable as well. You can do this when choosing the colour as well but casting is expensive so it's always worth doing it as few times as possible.

Now when you want to change the colour, drag your character / pawn reference into the blueprint, pull off the pin and choose the material instance reference you made and it's this you plug in to the Target pin.

\$\endgroup\$
  • \$\begingroup\$ Thank you very much for the reply, I am very new and bad of unreal, however good your explanation, I'm afraid I have to wait for the sending of your images, because I'm having many difficulties. You're not to blame. I'm really bad. \$\endgroup\$ – Boneco Sinforoso May 11 at 0:18
  • \$\begingroup\$ I made one more modification, now putting the function separately, there is no error, but I still can not set the collection. \$\endgroup\$ – Boneco Sinforoso May 16 at 23:18
0
\$\begingroup\$

Exactly at 5:37 minute of that video (same person as the first tutorial) I was able to figure out how to solve my problem:

https://www.youtube.com/watch?v=0CPFt_vEqfk&list=PLnwVxZ2WVVpl1sOPaEzK--4fXzq2ZQvE-&index=49

I realized that to call the function he first called the variable (get variable):

enter image description here

But no use, if I do not know the correct type of variable (as you can see in the image above, circled in pink).

Only write Material Instance when defining the variable type:

enter image description here

Of the 7 options I tested option 4 and option 7. The correct one is option 7 (circled in pink in the image above).

To deduce that this option was correct, I had to see the 5:40 moment of the video (https://www.youtube.com/watch?v=0CPFt_vEqfk&list=PLnwVxZ2WVVpl1sOPaEzK--4fXzq2ZQvE-&index=49):

enter image description here

Step by step:

enter image description here


Important addition.

For the color to be set correctly, you need to set this variable first.

Just add this code to the Contruction Script:

enter image description here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.