this should be an easy question, if you are familiar with C++ Programming, but I am quite new
I will describe this very easy:
I have made a plugin.
This Plugin contains a class.
Within the class there is a variable.
I have changed this variable in the Blueprint Editor via Set or a Function.
When i “Get” this variable in the Blueprint Editor, i get the right value.
BUT: This variable is used in a function that is also part of the class, but it seems that the function just takes the default value of the variable no matter how often i change the variable.
What do i have to do? Include other build jobs? I dont know
Thanks in advance
C++ Function or Blueprint Function? Can you show your code and screenshot of blueprints?
The Plugin is here:
(I have made a copy of ProcMeshComponent and changed a few things)
All the nodes are functions within the class.
SetupMesh sets a few variables, for example CollisionType = “Complex”.
The default value of this variable is “Simple”.
When i Get this variable, i get the right value: “Complex”
But: Within the function “CreateMeshSection” there is an if-then-statement with this variable and it never does the code inside cause CollisionType is not “Complex” at this point.
I hope it is clear
PS: Thanks for your fast reply.
So Create Mesh Section is C++ function or blueprint? can you pase code of it?
What is the if-then statement that you’re referring to in CreateMeshSection? I see where your SetupMesh function refers to CollisionType however I don’t see any mention of CollisionType in the CreateMeshSection function. Additionally, I tried to test this in a generic sense by adding a float variable in code and creating a function to Add to the variable as well as another function to Get the variable. Calling the Get function returns the current value of my variable even if I update the value inside the blueprint or with my Add function. Please let me know if I missed something about your plugin or if you can reproduce this outside of your plugin.
in my header file there is:
ECollisionType is an UENUM uint8 variable with entries: Simple, Complex
In the BP Editor i use the SetupMesh function to change the CollisionType to Complex.
If i that value afterwards, it works fine.
But CollisionType is in use within the function: CreateProcMeshBodySetup()
This function will be called when using CreateMeshSection(…)
Within CreateProcMeshBodySetup() there is this code snippet:
if (CollisionType == ECollisionType::Complex)
ProcMeshBodySetup->CollisionTraceFlag = CTF_UseComplexAsSimple;
But when i start the project, there is no complex collision created. And i have tested it. The conclusion was that the code within the if-then-statement was not called. Means that CollisionType is “Simple” at this point.
I know i have overseen something very easy
If you add a breakpoint at the if statement inside CreateProcMeshBodySetup(), what is the value of CollisionType when it’s called? Also, do you get the same issue if the calls are made in another class rather than inside a plugin?
Thanks for your advice. Now we come very close to the solution.
I have created a new variable called: ECollisionType TestCollisionType
We have three functions called sequentially:
CreateMeshSection --------> UpdateCollision ----------> CreateProcMeshBodySetup
I have tested it with just this line of code: TestCollisionType = CollisionType
I have put this code sequentially in those 3 functions and got the value of TestCollisionType.
It works perfectly in CreateMeshSection and UpdateCollision, but not in CreateProcMeshBodySetup.
The last function always takes “Simple” as value.
Here are the pics of what happens between “TestCollisionType = CollisionType” until the if-then-statement:
At the if-then statement the value is Simple even if it was “Complex”.
I have tested it more deeply.
When CollisionType is “Complex”, i get the right Print. So Test is also “Complex”, but within the function CreateProcMeshBodySetup() the value “Simple” is taken. Even forwarding the variable has no effect.
The Problem was the initialisation of ProcMeshBodySetup, so these lines of code:
ProcMeshBodySetup = NewObject(this);
ProcMeshBodySetup->BodySetupGuid = FGuid::NewGuid();
Because ProcMeshBodySetup has “transient” as UPROPERTY
and transient means that within the function where the initialization is, the function uses just the default values of every variable that is in use within that function.
When outside of that function, before or after that function, variables are handled as usual.