Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Overwriting Map Note Marker Model #2721

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ArshvirGoraya
Copy link

Mod Support:

I want to replace 3D models.
Currently, I'm just disabling the mesh renderer for models I want to replace and childing the new model to them.

Problem:

  • I can't do the above method for the map note model as well as I want: it renders the default model during the prompt for the notes message, and only after can the model be "replaced" with the above method.
  • See video of the problem: https://streamable.com/phfbu1

Solution:

  • Add a way to overwrite the 3D model for notes, so it creates the desired one by default.
  • Create customGameObjectUserNoteMarker:
    • if is null, just does what it does now.
    • if not, uses the customGameObjectUserNoteMarker game object for the Notes model.
  • See video of the solution working: https://streamable.com/3zm9nf

Example Usage:

void Start(){
	if (Automap.instance.CustomGameObjectUserNoteMarker == null){
		Automap.instance.CustomGameObjectUserNoteMarker = mod.GetAsset<GameObject>(PrefabName, false);
	}
}

Code Explanations

There are other code changes in the script, so here is an explanation of them:

  • Since we're using a prefab, it may have children, which needs to be handled.
    • For example, the parent of the prefab game object may just be an empty object containing all the children.
  • The children must be named correctly with the ID and prefix that a raycast uses to edit or remove the note, otherwise it will not detect them.
    • A new function is created for this: SetNameRecursively, which is just like the existing function SetLayerRecursively, but for naming.
    • Now that children can be detected with the raycast we can detect and edit the notes when the raycast hits any of the prefab's children.
  • We still need to handle deleting the note. The raycast detects an object with a specific name and then deletes it. But if its a child of a larger object, it will delete just that child, not the entire object. So, this needs to be handled.
    • A new function is created for this: GetHighestAncestorBelowAncestor, which finds the highest gameobject/parent from the raycast hit gameobject, that is still below a specified gameobject: in this case "UserMarkerNotes." Since the object with the name "UserMarkerNotes" stores all the notes, we know the parent object of the Prefab will be placed right under it. So, this function will simply go upwards parent-to-parent from the hit raycast object and get that parent. Now that the parent of the prefab can be gotten, we can delete the entire object, not just the single child that the raycast hit.
    • Note: there is a way to just let the modder handle this. For example, they can create a script that deletes the parent on a child's OnDelete() event. But they would have to attach this script to all of the children, which may be annoying, especially if there are a lot of children.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant