How to Access a Component (class) for a specific object
Closed this issue · 2 comments
Like the title says, I would like to ask how to Access a script attached to a specific Gameobject
in your Doc you Said that it's Possible to Get All instances of a Class
using FindGameobjectofType...
for example
auto playerControllerClass = UnityResolve::Get("Assembly-CSharp.dll")->Get("PlayerTargetCloser")
auto playerObjects = playerControllerClass->FindObjectsByType<UnityResolve::UnityType::GameObject*>();
and then iterate for each instance..
for (auto playerObject : playerObjects) { etc
But what if , i want to access a specific Component Script attached to A Specific gameobject : "Player1" using ..
UnityResolve::UnityType::GameObject* player1 = UnityResolve::UnityType::GameObject::Find("Player1");
i want to access the PlayerControllerClass of this Specific Gameobject that i found Using Find( ) function
an Other Question is
how to access an other component (script) that is Attached to this Player, i Already get the PlayerController gameobject instances
these gameobject instances have an other component HealthController
how to access them based on the gameobject instances we already found
auto playerControllerClass = UnityResolve::Get("Assembly-CSharp.dll")->Get("PlayerTargetCloser")
auto playerObjects = playerControllerClass->FindObjectsByType<UnityResolve::UnityType::GameObject*>();
for (auto playerObject : playerObjects) {
// here i want to get the HealthComponent Class of Each PlayerObject
And the Final Question
I want to
1 Find All Instances of PlayerController
for each gameobject instance of this class
i want to access this PlayerControllerCompont Because in it's Fields it have a reference to an other script called
playerbehaviour in the field --- (PlayerController._behaviour)
this playerbehaviour component (script) have a reference to an other Custom class in it's field
playerbehaviour._playerstatsTemplate
This Playerstats
Based on the dump is a custom class
(ObjectModel.Playerstats)
namespace: ObjectModel
Assembly: Assembly-CSharp.dll
AssemblyFile: Assembly-CSharp.dll
class Playerstats: Object {
+0X030 | System.String name;
+0X038 | System.String description;
+0X044 | System.Int32 stamina;
+0X050 | System.Decimal Weight;
i would be very thankful to you if you clarify on more how to use your tool, its very awesome, flexible
but a bit overwhelming
i tried Asking GPT4 OPUS GEMINI , none could give me the answer by the way )
thanks
For the first question, please refer to the Scripting Reference in the Unity Documentation.
For the second question, use UnityResolve::UnityType::GameObject::GetComponents(...).
For the last question, you can use the content in struct.hpp after dumping, make sure the struct member sizes match the in-game sizes.
i ended up using an other api and it was more practical and useful thanks anyways you can close this, as i already finished my project