Problem passing a variable in blueprints

I am currently trying to pass a variable from a weapon blueprint to the playerpawn blueprint in ShooterGame.
I used the support [here][1] as it seems to be the directions to follow, but I cannot get it to compile and when I try to hook up the Get Player Controller it says object var is not compatible with interface.

Hey,

The problem is, you’re using the wrong function to try and interface.

When you create an interface and it to a blueprint, you get two functions to call it. You get a method that will call the function inside the current blueprint, and another which will call the function inside an actor you have supplied.

What you need to do is, right click and type your function name ‘Weight Pass’, and two functions should come up. One will be under the ‘Interface Messages’ menu, that is the one you want. This will allow you to pass in an actor as a target.

Cheers,
Chris

Dear Emile,

In ShooterCharacter.h, the pawn class

/** get currently equipped weapon */
	UFUNCTION(BlueprintCallable, Category=Weapon)
	class AShooterWeapon* GetWeapon() const;

just call this, its already blueprintcallable (you may have to turn off context sensitive)

and then you can use the weapon blueprint callable functions you made in your previous thread :slight_smile:

Rama

PS: my function below with better coloring

#.h

UFUNCTION(BlueprintCallable, Category=Weapons)
void GetAllWeapons(TArray& AllWeapons);

#.cpp
void YourCharacterClass::GetAllWeapons(TArray& AllWeapons)
{
//make sure passed in array is empty
AllWeapons.Empty();
for ( TObjectIterator Itr; Itr; ++Itr )
{
AllWeapons.Add(*Itr);
}
}

I looked at this var but it seems to access only the variables in the weapons code. I am trying to GET information from the variable(s) created in the other blueprint.

Also this only accesses the currently equipped weapon, I would need to access all items/weapons in the inventory carried.

You seem to be doing coding in C++ as well as blueprints, the communciation system between Blueprints has already been completely overhauled and will be in a future version

if you can do the c++ route I can highly recommend that

just make the variables you want to access as:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=YourCategory)

#To access All Weapons

write your own function to access all the weapons using ObjectIterator

if you really want to use blueprints you could get the array of weapons and then use a foreach loop with that array (foreach loop accepts wildcard T arrays)

Make sure to call the function below the minimum number of times necessary, such as only when you know current inventory has changed or are not sure if it has changed.

If you never remove weapons but only reduce their ammo, you only need to call this each time a new weapon is added to player inventory

#.h

UFUNCTION(BlueprintCallable, Category=Weapons)
void GetAllWeapons(TArray& AllWeapons);

#.cpp
void YourCharacterClass::GetAllWeapons(TArray& AllWeapons)
{
//make sure passed in array is empty
AllWeapons.Empty();

  for ( TObjectIterator Itr; Itr; ++Itr )
  {
     AllWeapons.Add(*Itr);
  }
}

Sorry I am still learning and very slowly at that. I understand the basics of what you have here but implementation and execution I am falling short on.
I am trying to pass the ammo variable to the pawn as an example from all weapons carried in inventory and update the current ammo amount states. Once I have all the amounts then I add them together and display it.

I am trying to learn C++ as I am doing this so the programming is going very slow and also learning to do stuff in blueprints.

thanks

if you copy and paste my code above into your shootercharacter class, compile that,

then you can go into the editor and use that node in your character class connected to a ForEach loop

to check each weapon’s ammo count using the blueprintcallable functions you made in your previous thread :slight_smile:

Hi! Not sure how much help this is, but this is how I’m passing a variable (the weapon itself) from a weapon to my character in my game. You can also see how I attach it to the characters hand in the 3rd person. I’m not an expert myself and was just searching for help on something myself when I saw this question go pretty much unanswered for blueprint anyway, hope it helps someone.

Hello,

This is a question from the beta version of the engine. We are marking this answered for tracking purposes. If you are experiencing an issue similar to this please post a new question.

Thank you.