Variable doesn't seem to work from one blueprint to another.

Hello people.
I have made a grabbing system for my game. Now, the thing I’m struggling in is that I don’t want to be able to drop the object that I’m holding if it is overlapping something.


Up here is the method I used to get variables from other blueprints, I used this method between two blueprints, The Object’s blueprint and the main character’s blueprint. I connected the custom event to Event BeginPlay so it works.


Up here is from my Object’s blueprint where I detect if the box collision of the held Object is overlapping something. If it does then it prints something and vise versa. This seems to work well.
(Held Object variable is from main character’s blueprint).


Up here is from my main character’s blueprint. I used the IsOverlapping? variable which I made from the object’s blueprint to know if it the object is overlapping or not.

The issue that I’ve understood is that the IsOverlapping? variable doesn’t seem to work properly and I don’t know why.
Is there a better way to get variables from other blueprints?
Help would be appreciated.

Can you post a video or a link to a video highlighting this system so it can be tracked in real-time?

There may be other stiff you’re doing I’m unaware of.

1 Like

微信截图_20240422180127
You may have overlooked these!

I might have. Do you have an idea on how I would use them? I’m not a pro in this.

My actor object has a static mesh (cube) and a box collision as its root. I use the same blueprint to create many cubes in the scene.
If you could show me how it can be done, I would really appreciate it.

Here is the video showcasing on what’s happening.
The odd thing is, only 1 cube works (to not drop when overlapped). However, if I try it in standalone, no cube works to not drop when overlapped.

Btw, parent class of my character is ‘character’, and the object parent class is actor.

It looks like it’s a collision issue. Try disabling the collision and see what happens.

If I disable collision for the box collision, the OnComponentBeginOverlap will no longer detect the overlap. Plus, my the collision responses to different channels are all set to overlap.
Whatever I try, nothing works.

btw, in my blueprint. I made it so that whenever I pick up the object, I set the collision response to physicsbodies as ignore.

I don’t know what more to try.
I just know the issue is the variable ‘IsOverlapping?’ isn’t working the way I want it to be.

Hey @JazzJack3D

The problem with this implementation is that if your object overlaps several other objects, then you will also set the variable to 1, but if the object no longer overlaps one of the two overlapping objects, then the variable will be set to 0, but the object will still overlap the second of two overlapping objects
image

have you tried using node GetOverlappingActors?
image

@JazzJack3D
do you update the Variable Giver when you take a cube?

Yes, it seems I wasn’t clear enough.

What I meant is that you can disable the collision of the box that is being held. Then reenable its collision after you let it go.

The easiest way to do this is to create a basic box blueprint, retrieve the specific instance of the box, and adjust the collision settings of that instance:

Then when you decide to place it back down, you reenable the collision of that object.

However, make sure your basic blueprint box settings are like this:

Where you add a BOX COLLISION that is slightly larger than the box, and that the collision will only interact with whatever object type your character is. (Usually this is PAWN).

1 Like

I agree with what you said.
Would you mind showing me how I can use that node “Get Overlapping Actors”.
Sorry, I’m like a beginner, I don’t know how to use much stuff, although I understand the logic of them.

Here is a video showing more of my blueprint. I have already done the same concept, which is disabling collision when object is held, here it is:

I believe this is the same thing, correct me if I’m wrong.
btw, this is disabling collision for the static mesh only, not the box collision component.

Let me prepare everything you need and tomorrow I’ll describe how you can implement such game mechanics :wink:

No, you haven’t.

The video definitely helps, but you haven’t changed the collision value. You’ve only changed the collision response behavior.

Does that make sense?

You’re telling it what to react to, but you’re not actually setting the reaction.

You need to Enable/Disable Actor Collision, like I showed, or some equivalent.

I’ll leave you in the hands of Neot, but keep that in mind.

(To be more clear: “Collision Response” is like screening a call; it will only allow the query through if it meets a certain requirement. But to actually pick up the phone and talk, you need to SET COLLISION.)

Hello @JazzJack3D

To begin with, we will create the two collision channels we need, which we will use later:


The names can be anything you like; what’s important is setting the Default Response correctly.


Next, we will prepare the cube itself that we will be lifting.


The logic here is that the cube itself will be a physical body, subject to falling and other forces, while the collision box, which is its child, will generate overlap events and store all objects it overlaps with. This will be useful later on. The collision box stores them by default, so we won’t need to implement this ourselves.


Let’s set up the collisions:

For the cube, we need two channels—specifically, the ones we created: IntCubeTrace and IntCubeBox.
For the cube, we should set both of these channels to Ignore.


Also, don’t forget to enable Simulate Physics for the cube.


For the box, it is important to set IntCubeTrace to Block—this will be useful later. As for IntCubeBox, set it to Overlap—this will allow the cube to overlap with other cubes.

To allow the cube to overlap with the environment, set Overlap to the channels associated with the desired environment elements(“Object Type” parameter), typically World Static and World Dynamic.

It is also important to check the box for Generate Overlap Events .


To ensure that the box overlaps with environment elements, we need to make sure that the IntCubeBox channel of the desired element is set to Overlap (this should be the default setting, as we set the standard value for the IntCubeBox channel to Overlap).

Additionally, we need to check the box for Generate Overlap Events and ensure that the channel specified in the Object Type is set to Overlap in the box’s collision settings.


Now that we have set everything up, we can proceed with creating the logic in our character (I will work in the character’s event graph, where the camera rotation settings and other settings are located).

Here is everything we need to do; let’s break it down step by step:


This set of nodes will create a ray. The start of the ray is the world position of the camera, and the end of the ray is a point directly in front of the camera at a distance of 500 cm.

We choose IntCubeTrace as the channel, which we created earlier. As we recall, this channel overlaps only with the collision box of our cube, meaning the ray can only interact with it.

This node will return the actor the ray interacted with, which is the cube we are looking at. We’ll discuss the branch later.


Immediately after the ray returns the desired object, we perform a cast to our cube, allowing us to access its parameters and components. The cast also helps filter out irrelevant ray returns (such as if we are not looking at a cube or if the cube is beyond 500 cm).

Next, we save the cube actor in a variable of type IntCube Object Reference . We also retrieve the static mesh cube from the actor and save it in a variable of type StaticMesh Component Object Reference .

Then, we call the PickUpCube event, which we will discuss later.


This is the implementation of the PickUpCube event. This event attaches the cube to the camera and detaches it, while also toggling the physics simulation and collision for the lifted cube using the Change Cube Collision event (we will discuss this event later).

Additionally, the PickUpCube event manages the attached variable, which indicates whether the cube is lifted or not. This variable is used in the branch at the beginning.

Depending on the value of the pickup input, the event will either attach or detach the cube.


The ChangeCubeCollision event toggles the physics simulation and collision for the cube, depending on the value of the input Simulate .

When we pick up the cube, its collision and physics simulation are disabled, but the collision of the box continues to work. This allows the cube to move inside other objects while still being able to determine what our cube is overlapping with, using the collision of the box.


We just need to understand what happens if the attached variable results in true at the very beginning and the logic flows upward.

Here, we determine how many objects our cube is currently overlapping with. As we remember, we configured the collision channels for the box and environment elements, and we are using the result of those settings here.

We obtain an array of all the objects that the box has overlapped with and determine their quantity by checking the length of the array. If the length is greater than 0, it means the box is intersecting with something, so we don’t release the object and call the necessary logic to show an error, in my case, a print string. But if the length of the array is zero, it means the box is not intersecting with anything, and we can release it by calling PickUpCube and setting the input pickup to false .


This will help you understand collisions, how to set them up, and create logic for them. It will be very useful for working in Unreal Engine. :wink:

2 Likes

Thank you Neot111

I don’t know how to thank you for this.
Thank you so much, you deserve greatness in your life.

Just one issue


Everything works amazingly, just the way you showed and the way I wanted it to be.
Although I keep getting 4 errors, I don’t understand why.
Once again, thank you so much.

Also, I had to use break hit result for the line trace by channel. I don’t know how you got yours to have more outputs:


I don’t know if this is where the errors are coming from.

Right click on the “Hit Result” pin and select “Split Pin”. This does not only work on output pins but also on input pins. It also works “recursive”. This can be very handy, for example you can split a transform pin and inside that you can split the rotation pin and provide only the z-axis rotation as a float value.

Thank you. But the errors are still there.

I also realized that the error appeared once I pressed ‘f’ for the first time.
Also, pressing ‘f’ on a cube for the first time doesn’t work, only the second try and after that works.

When variables don’t seem to work from one blueprint to another in software development or game development using Unreal Engine, several factors could be causing the issue:

  1. Scope of Variables: Ensure that the variables are correctly scoped to be accessible across different blueprints. Variables can have different scopes like instance, class, or global, and their accessibility depends on how they are defined.
  2. Variable Initialization: Make sure that variables are properly initialized before being accessed in different blueprints. Uninitialized variables can lead to unexpected behavior or errors.
  3. Blueprint Communication: Use appropriate communication methods between blueprints, such as event dispatchers, interfaces, or function calls, to pass variables between them effectively.