#SO nested in mono nested in SO
1 messages · Page 1 of 1 (latest)
Not quite sure what you mean. Maybe share some code and/or screenshots.
You reference things wherever you need to access them. There's no rule about not sharing references.🤷♂️
public abstract class CharacterDataBase: ScriptableObject {
[Header("Base")]
[SerializeField] protected string characterID;
[SerializeField] protected string characterName;
[SerializeField][TextArea] protected string characterDescription;
[SerializeField] protected int maxHealth;
public string CharacterID => characterID;
public string CharacterName => characterName;
public string CharacterDescription => characterDescription;
public int MaxHealth => maxHealth;
}
[CreateAssetMenu(fileName = "Enemy Character Data", menuName = "NueDeck/Characters/Enemy", order = 1)]
public class EnemyCharacterData: CharacterDataBase {
[Header("Enemy Defaults")]
[SerializeField] private EnemyBase enemyPrefab;
[SerializeField] private bool followAbilityPattern;
[SerializeField] private List < EnemyAbilityData > enemyAbilityList;
public List < EnemyAbilityData > EnemyAbilityList => enemyAbilityList;
public EnemyBase EnemyPrefab => enemyPrefab;
public EnemyAbilityData GetAbility() {
return EnemyAbilityList.RandomItem();
}
public EnemyAbilityData GetAbility(int usedAbilityCount) {
if (followAbilityPattern) {
var index = usedAbilityCount % EnemyAbilityList.Count;
return EnemyAbilityList[index];
}
return GetAbility();
}
}
[Serializable]
public class EnemyAbilityData {
[Header("Settings")]
[SerializeField] private string name;
[SerializeField] private EnemyIntentionData intention;
[SerializeField] private bool hideActionValue;
[SerializeField] private List < EnemyActionData > actionList;
public string Name => name;
public EnemyIntentionData Intention => intention;
public List < EnemyActionData > ActionList => actionList;
public bool HideActionValue => hideActionValue;
}
[Serializable]
public class EnemyActionData {
[SerializeField] private EnemyActionType actionType;
[SerializeField] private int minActionValue;
[SerializeField] private int maxActionValue;
public EnemyActionType ActionType => actionType;
public int ActionValue => Random.Range(minActionValue, maxActionValue);
}
public class EnemyBase : CharacterBase, IEnemy
{
[Header("Enemy Base References")]
[SerializeField] protected EnemyCharacterData enemyCharacterData;
[SerializeField] protected EnemyCanvas enemyCanvas;
[SerializeField] protected SoundProfileData deathSoundProfileData;
protected EnemyAbilityData NextAbility;
So basically EnemyBase has a protected EnemyCharacterData field and EnemyCharacterData has an EnemyBase field and when you setup the scene you create the Data SO but put a gameobject that uses EnemyBase and when you create EnemyBase you put an SO inside it
And that's confusing
Ah, a "both ways dependency" it's not a great practice, but there's nothing critically wrong about it.
But what is the purpose? Isn't this a symptom of bad design?
In general it's a good practice to reduce dependencies as much as possible and this kind of double dependencies can usually be solved easily with a bit of refactoring. That being said, I'm not sure why the would need these 2 classes to depend on each other. Perhaps there's a good reason for it. Most often than not, it usually means bad code architecture though.
Yes, most likely.
Just because it's a serious project, doesn't mean that it doesn't have any bad practices.
The reason I'm seeing is, he uses the SO to store the data of floor enemies since it's a roguelike, then fetches the prefab from inside the so of the enemy and builds it this way
At my work we're porting some AAA game right now and I can confidently say there's some code that's worse than what you'll find in most indie games.
That sounds like there should be a separate object responsible for holding the references to the prefabs.
Something like EnemyDatabase or something.
Yeah makes sense
Since I'm new I'm trying reimplementing a roguelike with my spin following this example since I only found this one but sometimes I go like "this doesn't seem correct"
That's a good learning experience. I'm sure that there are good practices in the project too, but it's also important to investigate things that don't seem right to you.👍