gewoon_kiefer
gewoon_kiefer3w ago

destroy object with only realtime view

how do i destroy an object that has a realtime view but not a realtime transform?
10 Replies
kapa.ai
kapa.ai3w ago
Hi @gewoon_kiefer. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To destroy an object that has a RealtimeView but not a RealtimeTransform, you should use the Realtime.Destroy() method rather than Unity's standard GameObject.Destroy() method. This ensures that the object is properly destroyed across all clients in the room. Here's how to do it:
// To destroy a GameObject with a RealtimeView
Realtime.Destroy(gameObject);

// Alternatively, you can pass the RealtimeView component directly
RealtimeView view = gameObject.GetComponent<RealtimeView>();
Realtime.Destroy(view);
// To destroy a GameObject with a RealtimeView
Realtime.Destroy(gameObject);

// Alternatively, you can pass the RealtimeView component directly
RealtimeView view = gameObject.GetComponent<RealtimeView>();
Realtime.Destroy(view);
Both approaches will work the same way. The Realtime.Destroy() method must be used instead of Unity's GameObject.Destroy() for any objects that were instantiated with Realtime.Instantiate() or that have a RealtimeView component Room > Ownership and Lifetime Flags. It's worth noting that if the object is owned by another client and has preventOwnershipTakeover set to true, you may not be able to destroy it unless you're the owner. In such cases, it's generally recommended to have the client that owns the object destroy it:
if (realtimeView.isOwnedLocally) {
Realtime.Destroy(gameObject);
}
if (realtimeView.isOwnedLocally) {
Realtime.Destroy(gameObject);
}
This approach helps prevent errors that can occur when multiple clients try to destroy the same object simultaneously Room > Common Questions. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3w ago
<@899009432518803496> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
gewoon_kiefer
gewoon_kieferOP3w ago
i git this error:
Realtime: Could not find RealtimeViewModel for RealtimeView in the datastore. Unable to destroy RealtimeView.
Realtime: Could not find RealtimeViewModel for RealtimeView in the datastore. Unable to destroy RealtimeView.
Mechabit
Mechabit3w ago
can't destroy scene views and can't destroy stuff before proper connection
gewoon_kiefer
gewoon_kieferOP3w ago
i properly connected
Mechabit
Mechabit3w ago
you can only destroy stuff instantaited at runtime
gewoon_kiefer
gewoon_kieferOP3w ago
so i would need to spawn the object i want to destroy before i can destroy it?
Mechabit
Mechabit3w ago
if you need to destroy a scene object you can hide it instead
gewoon_kiefer
gewoon_kieferOP3w ago
oke how do you sync the
gameObject.SetActive(false);
gameObject.SetActive(false);
?
Mechabit
Mechabit3w ago
make a model with a bool and a target object

Did you find this page helpful?