#[repr(transparent)]pub struct GameObject(pub Object);Expand description
UnityEngine.GameObject: an object in the scene, which holds components.
use hao_il2cpp_unity::{ComponentType, GameObject, Transform, Vector3};
// A new object, parented under the game's player.
let marker = GameObject::new("marker")?;
if let Some(player) = GameObject::find("Player")? {
marker.transform()?.set_parent(player.transform()?, false)?;
marker.transform()?.set_local_position(Vector3::UP * 2.0)?;
let tf: Option<Transform> = player.get_component()?;
println!("player at {:?}", tf.unwrap().position()?);
}Tuple Fields§
§0: ObjectImplementations§
Source§impl GameObject
impl GameObject
Sourcepub const ASSEMBLY: &'static str = "UnityEngine.CoreModule"
pub const ASSEMBLY: &'static str = "UnityEngine.CoreModule"
The assembly (.dll name without the extension) that defines the class.
Sourcepub fn is_null(&self) -> bool
pub fn is_null(&self) -> bool
Whether this is a null reference. A destroyed object isn’t null;
check is_alive for that.
Sourcepub fn dont_destroy_on_load(&self) -> Result<()>
pub fn dont_destroy_on_load(&self) -> Result<()>
Keeps the object when a new scene loads. Only works for GameObjects;
for assets (Material, Texture2D) use set_hide_flags.
Sourcepub fn set_hide_flags(&self, flags: HideFlags) -> Result<()>
pub fn set_hide_flags(&self, flags: HideFlags) -> Result<()>
Sets the object’s HideFlags. HideFlags::HIDE_AND_DONT_SAVE keeps a
runtime-created asset from being unloaded on scene load.
Source§impl GameObject
impl GameObject
Sourcepub fn find(name: &str) -> Result<Option<Self>>
pub fn find(name: &str) -> Result<Option<Self>>
GameObject.Find(name): an active object by name or path, such as Canvas/Menu.
Sourcepub fn add_component<T: ComponentType>(&self) -> Result<T>
pub fn add_component<T: ComponentType>(&self) -> Result<T>
AddComponent(typeof(T)).
Sourcepub fn get_component<T: ComponentType>(&self) -> Result<Option<T>>
pub fn get_component<T: ComponentType>(&self) -> Result<Option<T>>
GetComponent<T>(), or None if the object has no such component.
Sourcepub fn transform(&self) -> Result<Transform>
pub fn transform(&self) -> Result<Transform>
The object’s transform, which every game object has.
Sourcepub fn rect_transform(&self) -> Result<Option<RectTransform>>
pub fn rect_transform(&self) -> Result<Option<RectTransform>>
The transform as a RectTransform, which objects with UI components have.
Sourcepub fn set_active(&self, active: bool) -> Result<()>
pub fn set_active(&self, active: bool) -> Result<()>
SetActive: shows or hides the object and its children; inactive
objects aren’t updated or drawn.
Sourcepub fn is_active(&self) -> Result<bool>
pub fn is_active(&self) -> Result<bool>
Whether the object itself is active (its own flag, ignoring parents).
Sourcepub fn is_active_in_hierarchy(&self) -> Result<bool>
pub fn is_active_in_hierarchy(&self) -> Result<bool>
Whether the object is active, taking its parents into account.
Sourcepub fn tag(&self) -> Result<String>
pub fn tag(&self) -> Result<String>
The object’s tag, which games use to label kinds of objects ("Player").
Sourcepub fn set_tag(&self, tag: &str) -> Result<()>
pub fn set_tag(&self, tag: &str) -> Result<()>
Sets the tag; it must be one defined in the game’s tag manager.
Sourcepub fn compare_tag(&self, tag: &str) -> Result<bool>
pub fn compare_tag(&self, tag: &str) -> Result<bool>
Whether the object has tag tag (CompareTag).
Trait Implementations§
Source§impl Clone for GameObject
impl Clone for GameObject
impl Copy for GameObject
Source§impl Debug for GameObject
impl Debug for GameObject
impl Eq for GameObject
Source§impl Hash for GameObject
impl Hash for GameObject
Source§impl Il2CppValue for GameObject
impl Il2CppValue for GameObject
Source§impl PartialEq for GameObject
impl PartialEq for GameObject
impl StructuralPartialEq for GameObject
Auto Trait Implementations§
impl Forget for GameObject
impl Freeze for GameObject
impl Move for GameObject
impl RefUnwindSafe for GameObject
impl Send for GameObject
impl Sync for GameObject
impl Unpin for GameObject
impl UnsafeUnpin for GameObject
impl UnwindSafe for GameObject
Blanket Implementations§
impl<T> AsId for T
impl<T> AsIdSalt for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more