x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

C++ Alter material during runtime

I am trying to ramp up the emissive brightness when the user presses a button (or moves a controller stick). I had it working with a combination of Dynamic material instance and timeline in the Blueprint editor, but I have found nothing that works in creating a C++ version. And to make matters worse, if I put some bad code in the C++ file in Xcode and hit compile, it crashes the app and I have to remove the offending code, and trash the Build folder just to get the editor to reopen. >:( I cannot figure out how to: 1... Access the material that is already set on the mesh. (Should that material be the regular material or should it be the material instance?) 2... Change the two parameters I created in the material for different brightness floats. 3... Use a timeline or curve to ramp up the material property, then bring it back down when the button is release.

Any help is MUCH appreciated. (I have no code to show because I had to take out the mess I tried.)

Edit: If anyone knows of a working code sample, that would be fantastic.

Product Version: UE 4.8
Tags:
more ▼

asked Aug 28 '15 at 06:53 PM in C++ Programming

avatar image

jesshmusic
1 2 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

Hm, just some ideas: 1. Try FindObject ? 2. You'll need to use a material instance to dynamically change the material parameters: See class UMaterialInstanceDynamic (e.g. ENGINE_API void SetScalarParameterValue(FName ParameterName, float Value); to set a scalar parameter value in a material instance) 3. Maybe do something like: OnClicked, OnReleased. And while it's clicked (that is OnReleased hasn't been called) use some FMath interpolation to interpolate your brightness variable.

Hope it helps a bit.

more ▼

answered Aug 29 '15 at 02:03 AM

avatar image

Timoses
86 14 13 22

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

It seems my issue was in attempting to assign the UMaterialInstanceDynamic in the constructor. I moved that to an override of BeginPlay() and now it works fine. Now I just need to figure out utilizing a curve to gradually ramp up the brightness over a couple seconds.

more ▼

answered Aug 29 '15 at 01:19 PM

avatar image

jesshmusic
1 2 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

InterpEaseInt and InterpEaseOut?

 MyBrightness = FMath::InterpEaseIn<float>(MyBrightness, MyDesiredEndBrightness, DeltaTime, 2.0f)

I hope this is the correct way of using this function.

more ▼

answered Aug 29 '15 at 02:22 PM

avatar image

Timoses
86 14 13 22

avatar image jesshmusic Aug 29 '15 at 03:42 PM

It's good in theory, but I would need to move my change in brightness to Tick() and then find a way to have it easing in when the axis or button is engaged, then ease out after. That was easy to do in the Blueprint using a Timeline curve, but I am still foggy on how to do it in C++. ;)

avatar image Timoses Aug 29 '15 at 07:20 PM

I don't know the Timeline blueprint stuff : s.

There is UTimelineComponent.

You will have to hand in a function though that will handle the interpolation of the value. What exactly does one have to specify in the blueprint timeline to get interpolation to work?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question