✨Mike the Floof Wizard✨
✨Mike the Floof Wizard✨
NNormal
Created by ✨Mike the Floof Wizard✨ on 3/17/2025 in #🤝ask-a-question
Cant destroy object
@Normcore Assistant how do i request ownership from a parent object
75 replies
NNormal
Created by ✨Mike the Floof Wizard✨ on 3/17/2025 in #🤝ask-a-question
Cant destroy object
No description
75 replies
NNormal
Created by ✨Mike the Floof Wizard✨ on 3/17/2025 in #🤝ask-a-question
Cant destroy object
No description
75 replies
NNormal
Created by ✨Mike the Floof Wizard✨ on 3/17/2025 in #🤝ask-a-question
Cant destroy object
@Normcore Assistant i am still getting the same error on line 28
75 replies
NNormal
Created by ✨Mike the Floof Wizard✨ on 3/17/2025 in #🤝ask-a-question
Cant destroy object
No description
75 replies
NNormal
Created by ✨Mike the Floof Wizard✨ on 3/17/2025 in #🤝ask-a-question
Cant destroy object
@Normcore Assistant my bossParts model gets the following error: The type 'int' cannot be used as type parameter 'TValue' in the generic type or method 'RealtimeArray<TValue>'. There is no boxing conversion from 'int' to 'Normal.Realtime.Serialization.IModel'.
75 replies
NNormal
Created by ✨Mike the Floof Wizard✨ on 3/17/2025 in #🤝ask-a-question
Cant destroy object
@Normcore Assistant I get an Duplicate 'RealtimeModel' attribute error on my BossPartModel
75 replies
NNormal
Created by ✨Mike the Floof Wizard✨ on 3/17/2025 in #🤝ask-a-question
Cant destroy object
@Normcore Assistant Which of these 2 models would i use for this script?
using Normal.Realtime;
using System.Collections.Generic;
using UnityEngine;

public class BossPartsManager : RealtimeComponent<BossPartsModel>
{
[SerializeField] private List<BossPartHealth> bossParts = new List<BossPartHealth>();
private SpawnBoss spawner;
protected override void OnRealtimeModelReplaced(BossPartsModel previousModel, BossPartsModel currentModel)
{
// Initialize model if needed
}

void Start()
{
// Find all child parts
bossParts.AddRange(GetComponentsInChildren<BossPartHealth>());
}

void Update()
{
// Check if all parts are destroyed
bool allPartsDestroyed = true;
foreach (var part in bossParts)
{
if (part != null && part.IsAlive())
{
allPartsDestroyed = false;
break;
}
}

if (allPartsDestroyed && spawner != null)
{
// All parts destroyed, destroy the whole boss
Realtime.Destroy(spawner.bossInstance);
}
}

public void SetSpawner(SpawnBoss spawnerRef)
{
spawner = spawnerRef;
}
}
Then create a part-specific health script:
csharp
public class BossPartHealth : RealtimeComponent<BossPartModel>
{
[SerializeField] private int maxHealth;

protected override void OnRealtimeModelReplaced(BossPartModel previousModel, BossPartModel currentModel)
{
if (currentModel != null && currentModel.isFreshModel)
{
currentModel.maxHealth = maxHealth;
currentModel.currentHealth = maxHealth;
}
}

private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Ball") || other.CompareTag("Bullet"))
{
model.currentHealth--;

if (model.currentHealth <= 0)
{
// Destroy just this part
Realtime.Destroy(gameObject);
}
}
}

public bool IsAlive()
{
return model != null && model.currentHealth > 0;
}
}
using Normal.Realtime;
using System.Collections.Generic;
using UnityEngine;

public class BossPartsManager : RealtimeComponent<BossPartsModel>
{
[SerializeField] private List<BossPartHealth> bossParts = new List<BossPartHealth>();
private SpawnBoss spawner;
protected override void OnRealtimeModelReplaced(BossPartsModel previousModel, BossPartsModel currentModel)
{
// Initialize model if needed
}

void Start()
{
// Find all child parts
bossParts.AddRange(GetComponentsInChildren<BossPartHealth>());
}

void Update()
{
// Check if all parts are destroyed
bool allPartsDestroyed = true;
foreach (var part in bossParts)
{
if (part != null && part.IsAlive())
{
allPartsDestroyed = false;
break;
}
}

if (allPartsDestroyed && spawner != null)
{
// All parts destroyed, destroy the whole boss
Realtime.Destroy(spawner.bossInstance);
}
}

public void SetSpawner(SpawnBoss spawnerRef)
{
spawner = spawnerRef;
}
}
Then create a part-specific health script:
csharp
public class BossPartHealth : RealtimeComponent<BossPartModel>
{
[SerializeField] private int maxHealth;

protected override void OnRealtimeModelReplaced(BossPartModel previousModel, BossPartModel currentModel)
{
if (currentModel != null && currentModel.isFreshModel)
{
currentModel.maxHealth = maxHealth;
currentModel.currentHealth = maxHealth;
}
}

private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Ball") || other.CompareTag("Bullet"))
{
model.currentHealth--;

if (model.currentHealth <= 0)
{
// Destroy just this part
Realtime.Destroy(gameObject);
}
}
}

public bool IsAlive()
{
return model != null && model.currentHealth > 0;
}
}
75 replies
NNormal
Created by ✨Mike the Floof Wizard✨ on 3/17/2025 in #🤝ask-a-question
Cant destroy object
@Normcore Assistant I see you are using a BossPartsModel in the manager script. Can you show me what BossPartsModel looks like
75 replies
NNormal
Created by ✨Mike the Floof Wizard✨ on 3/17/2025 in #🤝ask-a-question
Cant destroy object
@Normcore Assistant The destroy works now, but my bossBodyInstance is an empty with 4 children attached to it. If i hit 1 of these children everything gets destroyed, how do i give each child a seperate health bar
75 replies
NNormal
Created by ✨Mike the Floof Wizard✨ on 3/17/2025 in #🤝ask-a-question
Cant destroy object
No description
75 replies
NNormal
Created by ✨Mike the Floof Wizard✨ on 3/17/2025 in #🤝ask-a-question
Cant destroy object
@Normcore Assistant i am still getting the same nullreference exception. At line 25 of my BossHealth script. Somehow the script cant find my bossInstance
75 replies
NNormal
Created by ✨Mike the Floof Wizard✨ on 3/17/2025 in #🤝ask-a-question
Cant destroy object
@Normcore Assistant I tried using my commented code for managing the bosshealth but i am still getting the same nullreference exception
using Normal.Realtime;
using UnityEngine;


public class BossHealth : RealtimeComponent<BossMoveModel>
{
[SerializeField] private int maxHealth;
[SerializeField] private int currentHealth;
private SpawnBoss spawner;


private void Start()
{
model.currentHealth = model.maxHealth;
//currentHealth = maxHealth;
spawner = GetComponent<SpawnBoss>();

}

void Update()
{
if (model.currentHealth <= 0)
{
//gameObject.SetActive(false);
Realtime.Destroy(spawner.bossInstance);
Realtime.Destroy(spawner.bossBodyInstance);
}

/*
if (model != null)
{

}*/
}

private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Ball") || other.CompareTag("Bullet"))
{
model.currentHealth--;
}
}

public void SetSpawner(SpawnBoss spawnerRef)
{
spawner = spawnerRef;
}
}
using Normal.Realtime;
using UnityEngine;


public class BossHealth : RealtimeComponent<BossMoveModel>
{
[SerializeField] private int maxHealth;
[SerializeField] private int currentHealth;
private SpawnBoss spawner;


private void Start()
{
model.currentHealth = model.maxHealth;
//currentHealth = maxHealth;
spawner = GetComponent<SpawnBoss>();

}

void Update()
{
if (model.currentHealth <= 0)
{
//gameObject.SetActive(false);
Realtime.Destroy(spawner.bossInstance);
Realtime.Destroy(spawner.bossBodyInstance);
}

/*
if (model != null)
{

}*/
}

private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Ball") || other.CompareTag("Bullet"))
{
model.currentHealth--;
}
}

public void SetSpawner(SpawnBoss spawnerRef)
{
spawner = spawnerRef;
}
}
75 replies
NNormal
Created by ✨Mike the Floof Wizard✨ on 3/17/2025 in #🤝ask-a-question
Cant destroy object
@Normcore Assistant I am now spawning it correctly from one script. But when i try to destroy it in another script i get a nullreferenceexception
using Normal.Realtime;
using UnityEngine;


public class BossHealth : RealtimeComponent<BossMoveModel>
{
[SerializeField] private int maxHealth;
[SerializeField] private int currentHealth;
private SpawnBoss spawner;


private void Start()
{
//model.currentHealth = model.maxHealth;
currentHealth = maxHealth;


}

void Update()
{
if (currentHealth <= 0)
{
//gameObject.SetActive(false);
Realtime.Destroy(spawner.bossInstance);
Realtime.Destroy(spawner.bossBodyInstance);
}

/*
if (model != null)
{

}*/
}

private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Ball") || other.CompareTag("Bullet"))
{
currentHealth--;
}
}
}
using Normal.Realtime;
using UnityEngine;


public class BossHealth : RealtimeComponent<BossMoveModel>
{
[SerializeField] private int maxHealth;
[SerializeField] private int currentHealth;
private SpawnBoss spawner;


private void Start()
{
//model.currentHealth = model.maxHealth;
currentHealth = maxHealth;


}

void Update()
{
if (currentHealth <= 0)
{
//gameObject.SetActive(false);
Realtime.Destroy(spawner.bossInstance);
Realtime.Destroy(spawner.bossBodyInstance);
}

/*
if (model != null)
{

}*/
}

private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Ball") || other.CompareTag("Bullet"))
{
currentHealth--;
}
}
}
75 replies