Variable won't update after assignment.
I've got two scripts: In script one I have the following variables that are filled from somewhere else. I can see they have appropriate values in the inspector.
public string name;
public int str;
public float hp;
public string attackType;
The second script is a placeholder and takes it values from the previous script:
public string placeName;
public int placeSTR;
public float placeHP;
public string placeAttackType;
To update the second script, I use a third script that acts as a mediator:
placeholder.placeName = original.name;
placeholder.placeSTR = original.str;
placeholder.placeHP = original.hp;
placeholder.placeAttackType = original.attackType;
Now, the first three values will update just fine, but unity refuses to perform the fourth. If I include a debug log to output the attackType string within the third function like so:
placeholder.placeName = original.name;
placeholder.placeSTR = original.str;
placeholder.placeHP = original.hp;
Debug.Log(original.attackType);
placeholder.placeAttackType = original.attackType;
The console spits out the attackType string from the first script just fine, correctly. So I know the value is assigned properly, I know that the update script can see it and recognize it correctly, but it just refuses to admit it exists for the purpose of being given to the placeholder.
I'm at my wits end here, I have no idea why it might be doing this. Any clues?
post your code as everything there is fine so far. Something must be going on elsewhere.
Answer by Kirchesch · Mar 05, 2019 at 08:52 PM
Open your text editor press CTRL + F and digit attackType Do it in all your classes that have attackType and check if you are not setting it's value somewhere else. Try settping the placeAttackType = "" before setting it too
Thanks! This variable was part of a tree of variables with very similar names. One side of the assignment block hadn't been changed from the ctrl+c I used to set it up quickly.