How to Undo Collision Effects

I’m in the process of creating a puzzle demo in Unreal Engine 4.27. The puzzle involves lining up cubes so that they carry an electric energy from one point to another. Right now, metal cubes that touch a starting cube change gold when powered. But, when they are pushed away and are no longer touching that starting cube, they stay powered (as indicated by the material assigned as the “powered material”). So, how do I basically remove the “powered” and “found power” conditions, considering those two and “conducts” are Boolean variables? Here is a sample of part of the UE Blueprint.

Your help is greatly appreciated!

I think your problem may be that once they have power, they’re on and that’s it?

Even if you move them away, they still have power.

What about only making the original cubes powered, and the others take power from there, but never become powered themselves. Then, when you move them away, they will power off.

BTW, doing this on tick is not a good idea. You only need to update each cube’s status when one of them is moved, not every frame! :wink:

1 Like

That is a good question. The visible cubes are actually children to the Cube_BP’s parent. So, from a friend’s advice, I made child entities from the base settings. I did, however, think of throwing something more specific in after the parent function is carried out for the metal cubes that are supposed to conduct when touching a starting cube and lose power when not touching.

Regarding the tick, should I remove the nodes after that on the base BP? And yes, the cubes stay powered after touching. (Sorry, I forgot to add that part when I first answered.)

Things would get a lot easier for you, if you embrace object programming, which is what blueprint and all the UE concepts are pointing to.

Make a single cube blueprint, write the code it needs to know about, and just drop a load of them in the level.

Much easier than writing the kind of ‘controller’ program you have :slight_smile:

Regarding the Tick, nothing should be on tick in this scenario.

Tell me if you want elaboration on the blueprint concept. I think you can do all the cubes ( metal and plastic? ) with one BP.

1 Like

I thought I could use either BP or C++, though I’m not exactly a C++ expert. But doesn’t UE also use Python?

Actually, I have three types of cubes that appear in the level: a starting cube that is always powered and conducts and has energy; metal cubes which conduct but start with no energy; and rubber cubes, which block out energy entirely.

I guess I should remove everything after the tick in the source Cube_BP, then. I would like some elaboration with some examples, please, since I learn by example and by doing.

Sure thing, gimme a little while…

1 Like

Ok. So I made just one cube BP:

You see I have the cube, and the collision volume, and two variables. Power = this is a power cube, Rubber = this is a rubber cube.

You can drop them in the level, and check those variable accordingly.

The rubber cube and power cube don’t need any code, because they don’t care about anything else. In the ones that are intended to be metal ( power = no, rubber = no ), I have this:

When I overlap anything ( and I am not powered or rubber ), if it’s a cube with power, turn on the material.

When I stop overlapping stuff, set my material to off, but if I’m still overlapping a cube with power, turn the material back on again.

Obviously I haven’t implemented the material change and cube movement, but I hope you get the idea.

1 Like

I kind of get the idea. But, in my code, I currently have three Boolean variables: 1) Is Powered? which determines if a cube is carrying energy; 2) Conducts? which determines if a cube can carry energy when touching a powered cube; and 3) Found Power? which determines if a cube has found energy by touching a powered cube. Given this, would I have to add the Power and Rubber variables, or replace them with the Power and Rubber ones, especially considering that metal and starting cubes need to conduct energy?

Believe you can simply this with:

  1. bCanConduct
  2. bIsPowered

If it can conduct defines if its metal or rubber (can conduct or not). Is power defines the state of the cube; true if is charged, false if its depleted. bIsPowered can only be true if bCanConduct is true.

1 Like

The point to take away, is not which variables you have, but that only one cube needs code in it.

No code need anywhere else. No manager blueprint etc.

2 Likes

You mean those as functions?

So you’re saying it’d be better to make individual cubes with their own BPs, rather than parent and child ones?

No. I’m saying put the code in the cube(s), not outside.

I started down the path of parent and child, but realized none of them had code apart from the metal cube, and so just made one blueprint.

But I don’t really know your whole rule base.

1 Like

Maybe it would be best if I uploaded the whole project onto my Google Drive, and you can download and look at it from there. Would that be okay?

Yup, do that :slight_smile:

( Using reply is better, then I get a notification ).

Okay. I’ll post a link, once the upload is complete.

(And I noticed that, which was why I deleted my reply after noticing it wasn’t a reply to your last response.)

1 Like

Here you go.

Please have a look and let me know what changes I can make to the blueprints. Thanks so far!

Right…

Is a cube supposed to keep the power, even after disconnect?

Ok, this is it.

In the parent cube:

Construction script

image

and that is

Begin overlap ( notice, you don’t need all those overlap boxes ):

End overlap:

That’s it. No code anywhere else, nothing on tick :slight_smile:

cubes