Is it possible to change FlexContainer values at runtime?

For example changing the cohesion value of a fluid at runtime would be interesting.

Is it possible atm?

well, yes and no

I am currently writing my thesis about this, and chaning parameters at runtime is one of the hacks I’m doing.

I will keep you up to date. Here is what I have so far:

Find StaticMesh.h (NOT StaticMeshActor!)
and make
“class UFlexAsset* FlexAsset;”
accessible for blueprint by adding

“UPROPERTY(EditAnywhere, BlueprintReadWrite, Instanced, Category = Flex)”
ends up like this:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Instanced, Category = Flex)

class UFlexAsset* FlexAsset;

now find FlexAsset.h and do the same to: (just add BlueprintReadWrite)
UFlexContainer* ContainerTemplate;

now go to FlexContainer.h and add “BlueprintEditable” to the parameters you want to change

THIS SUCKS, because you are accessing an asset and not an instance!
I am currently working on an approach to change that, so you don’t violate the rule “keep data away from code”

PS: just noticed you asked this long ago… probably won’ need to keep you up to date^^

Hey man thanks for the reply, ive also done my theses with this and had a hard time to figure out how to change whatever i want at runtime and on the instance.

Here the tip that will save you a lot of time (belive me): Do not use FlexExt but plan Flex API. (If you want to change whatever you want on runtime on instances). Is lot of work, youll see why.

I see, thx for the tip

would you mind showing me your thesis? Anything I don’t need to figure out myself would help :smiley:
I would mention your name, of course

Do you guys have any updates. I am trying to change flex values in blueprint, too. But i did not manage to since I am not good with visual studio I only do blueprints :confused:

If you don’t want to or cannot do any C++, then this is going to be hard for you.

At least the FleX-Version I worked with (ver 0.9) did not have that option from the start, so to change Values at runtime, you’ll need to hack around a bit.

That’s sad I really wanted to be able to do this for my game :frowning: I tried to do what you explained in your first post without C++ knowledge but it gave me compile errors. I found the StaticMesh.h added:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Instanced, Category = Flex)

class UFlexAsset* FlexAsset;

Than I hit build. And it already gave me errors. I did not really know in witch line i had to add it so i put it under the headers.
Sorry if i ask to much from you but could you explain what changes you did in visual studio so I can redo it without the need of c++ knowledge? Because after that’s done I can change values in in BP and from there on i should be fine.

edit: i am using the currently newest flex version for UE 4.12

sure can do
I’ll make a series of images or so, that should be the easiest way.

Are you in a hurry or is it ok if you get it by the end of the week?

Thanks you are awesome! No hurry at all take your time! :slight_smile:

No hurry but I just wanted to ask if you are still considering to make the tutorial :slight_smile:

yes, just had some issues with my PC
sry for the delay, but my weekend is free so you get your info tomorrow :slight_smile:

I am currently struggling with the installation, my old version is gone -.-

meanwhile, I have a few questions, so I can give you more precise answers:

  1. do you use staticMeshes, ParticleSystems ort both?
  2. do you want to use a container more than once in a a level, e.g. two sources of water or two wobbly cubes?

currently working on your tutorial, should be done by the evening

right then, I just found out that the flex-version of the engine won’t work with update 3 on visual studio, so I can’t actually do any coding right now. sorry about that :confused:
but I can tell you what you need to do:

find the following files in visual studio:
installation_folder/Engine/
Source/Runtime/Engine/Classes/PhysicsEngine/FlexAsset.h”
installation_folder/Engine/
Source/Runtime/Engine/Classes/PhysicsEngine/FlexContainer.h”
installation_folder\Engine\Source\Runtime\Engine\Classes\Engine\StaticMesh.h”

in StaticMesh.h:
{
find the line:
“class UFlexAsset* FlexAsset;”

above that line, there should be “UPROPERTY(something)”. add “BlueprintReadWrite” to the parameter-list, should look like this:

106460-exampleone.png

}

in FlexAsset.h:
find:
“UFlexContainer* ContainerTemplate;”

same trick here, result should be:

in FlexContainer.h:

For every parameter you want to change at runtime, modify the UPROPERTY-parameter-list. I this example, I did it for ParticleFriction, Restitution and Adhesion:

how to use:
Get a reference to the StaticMesh that you use with Flex.
From the reference, use “Get FlexAsset”.
From the Asset, use “Get FlexContainer”

From the container, you should have getters and setters for every parameter of which you modified the UPROPERTY.

IMPORTANT NOTE DO NOT IGNORE:

if you use this at runtime, the Container will NOT (repeat: NOT) jump back to the parameter-values it had at start. it will keep the last entry.
Set this variables to CONSTANT to make sure you don’t accidentally mess them from a blueprint.
In your Event “BeginPlay”, read the values from your variables and write them into the flexcontainer.

this is a bit messy, true, but a proper solution takes a whole lot of c+±coding.

Hope this helps you :slight_smile:

Thank you so much! :slight_smile: It works like a charm! You don’t even know how much you helped me out I was looking for being able to do this over a year now :smiley: