#archived-code-general

1 messages ยท Page 383 of 1

warm cosmos
#

gotcha

warm cosmos
#

oh hm, colliders use the physics engine to do callbacks, that's not gonna work for my case

normal isle
#

guys any one online i want to talk about a tecnique used byt all games. how do they decide which task or action to perform at specific point in game ? like i have 40-50 task or action to perform how do idecide which to perform?

cosmic rain
normal isle
#

like i have a charcter whcih has to perform multiple task like climbing pickup object rotet object dragg object ladder climbing rope clicmbing engine start action stop action lever movemnt in specify direction so how to decide which action to perform?

#

like 'Inside' game it has so many action to perform at specific time

cosmic rain
#

Well, depends on the context...
If you interact with a ladder, you obviously want to climb, not try to start an engine.

normal isle
cosmic rain
#

As for "like 'inside' game" I've no clue what you mean. Can you do these things "outside" the game?

normal isle
cosmic rain
cosmic rain
normal isle
#

ok i want to make a game similar to "inside" and this game has lots of actions like ladder climb door openr opject push pull rope climb edge hanging and so many action i want to decide whcih action to perform in my game. i have 5 type of switch each swithc need dirrent timing and diffrnt animation so i want to decide perfeactly.

cosmic rain
#

Ah, okay. So you were talking about a different game. Never heard of it, so don't know how it works in that game.

But you most likely want to use polymorphism in your actions system.

normal isle
cosmic rain
normal isle
#

ok stiil my question is same i want to check whcih action to perform hwo to decide . do i need swithc statement for this?

warm cosmos
#

dlich do you know if unity has something like a spacial hash, or anything that will let me performatively do things like "find all nearby objects in radius"

#

this is what I was trying to figure out earlier with bounding boxes and colliders

#

if not I'll just implement one myself

#

it sounds like you want a state machine @normal isle

cosmic rain
warm cosmos
#

if you didn't see it I wouldn't have minded either

cosmic rain
warm cosmos
#

and that's all good

cosmic rain
warm cosmos
#

I wonder how it's possible to modify a basic spatial hash grid to be capable of lookups like

#

"all objects that can move"

#

or "all objects of a specific type"

#

maybe for the second one I can just have an ID associated with any object in the grid

cosmic rain
#

Maybe implement it in the simplest way first, using lists or dictionaries and position checks.
You might not even need any optimizations.

west lotus
unborn elm
#

How would one go about building and implementing an interface similar to the built in ones like OnMouseOver that has built in triggers?
Thinking of a thing like OnEnemyDied. Right now i just doing an static event and thats great in some cases I think that an interface that have a function that triggers by default could be cleaner.

#

The problem is that interface methods don't implement a body so I don't understand where to put the logic

wicked scroll
unborn elm
wicked scroll
lean sail
wicked scroll
#

there are the interface ones like IPointerClickHandler which you could replicate as well, but it's still basically the same process, just more explicit

lean sail
unborn elm
unborn elm
#

Or exit

#

Or click handler

#

Sorry for the confusion are trying to get my kids not to kill each other while i write. Not to good with the multi tasking

unborn elm
#

So does anyone know a bit more how those work? Is it just a loop through everything checking if the implement the interfaces or are there smarter ways?

hushed widget
#

Using GL.wireframesetting when rendering some debug stuff, I noticed it seems not possible to adjust this so that some objects are rendered in wireframe mode, and others are solid - is that right? The docs seem to suggest so too.

lean sail
# unborn elm So does anyone know a bit more how those work? Is it just a loop through everyth...

Looping through everything just to get around events sounds horrible.
You should really just make a base class as I said above, and in that base class do whatever subscriptions you want with the events. The stuff like IPointer sounds different from your case, at least in that case the raycast is directly targeting the objects its calling methods on. In your case, it seems like you want to be able to call this method on every instance. Im also really not sure why you just want interfaces here.

unborn elm
# lean sail Looping through everything just to get around events sounds horrible. You should...

Loopigng isnt an option, mentioned that because it was suggested as a solution.

Base class would be less flexible then my current implementation so thats not an option. This is not something that I actually need I just though that it could be nice to have an interface that gives me functions that are triggered by a given event.
The IPoint interfaces are interesting to me since the implement functions that gets called without adding subscriptions.
Seems like it works for the built in interfaces since they inherit from IEventSystemHandler so that might be an option to look into

lean sail
#

Which is entirely different and cannot be applied to calling a method on every instance of an object

unborn elm
unborn elm
lethal girder
#

how to fix the variable reset issue?

lean sail
# unborn elm Who do you do a raycast and get component with an interface? That is the interes...

Are you familiar with c# or just other OOP languages outside of unity? I feel theres a massive misunderstanding here about what the interface is actually doing.
The interface literally only declares that certain functions will be implemented on a class. It doesnt do anything else. Other classes will run logic and try to GetComponent/call functionality on your interface. Theres no subscribing here, because as I said this isnt calling a function on every instance of a script. Its directly calling the method on the object it finds.

lethal girder
# lethal girder how to fix the variable reset issue?

I am making a game where you can buy weapons. You have 9000 gold and want to buy a weapon for 7500 gold and the end value is 1500. but when i buy another weapon, it starts again from **9000 **and makes it -3000 gold, cuz the other weapon costs 3000 gold

I use PlayerPrefs, but I still often get the issue

lethal girder
# cosmic rain Share the relevant code
public int currentGold;

void Start()
{
    if (PlayerPrefs.HasKey("CurrentGold"))
    {
        currentGold = PlayerPrefs.GetInt("CurrentGold");
    }
    goldAmount.text = $"{currentGold}/{maxGold}";
}

public void BuySwordWeapon()
{
    try
    {
        SubtractGoldAmount(sword_prize);
        if (isPurchasable)
        {
            buySwordButtonText.text = "Owned";
            SetButtonInteractable(false);
        }
        else { }
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }
}

void SubtractGoldAmount(int prize)
{
    if (currentGold >= prize && currentGold != 0)
    {
        Debug.Log("1. CurrentGold: " + currentGold);
        currentGold -= prize;
        goldAmount.text = $"{currentGold}/{maxGold}";
        isPurchasable = true;
        Debug.Log("2. CurrentGold: "+currentGold);
        PlayerPrefs.SetInt("CurrentGold", currentGold);
        PlayerPrefs.Save();
    }
    else {
        isPurchasable = false;
        Debug.Log("Not enough gold to purchase this item!");
    }
}
cosmic rain
lethal girder
#

when i want to buy another weapon

cosmic rain
maiden heath
#

State.cs

public abstract class State
{
    protected StateMachine<State> StateMachine;
    protected State SuperState;

    public State(StateMachine<State> stateMachine)
    {
        StateMachine = stateMachine;
    }
}

CharacterState.cs

public abstract class CharacterState : State
{
    protected new CharacterStateMachine StateMachine;

    public CharacterState(CharacterStateMachine stateMachine) : base(stateMachine) { }
}

StateMachine.cs

public class StateMachine<T> : MonoBehaviour where T : State { }

CharacterStateMachine.cs

public class CharacterStateMachine : StateMachine<CharacterState> { }

On line 5 of CharacterState.cs, an error on base(stateMachine)
CS1503: cannot convert from CharacterStateMachine to StateMachine<State>

CharacterStateMachine inherits from StateMachine<CharacterState>, while CharacterState inherits from State
Not sure what the issue is, help is appreciated notlikethis

lethal girder
cosmic rain
lethal girder
cosmic rain
cosmic rain
cosmic rain
# lethal girder Yes

Well, then think a bit. You have a field in each of these scripts that gets initialized on start. Changing that field in one of the scripts does not affect the others. Makes sense?

lethal girder
#

To save values

#

its lil bit better now, but still the initializing of the game makes the issue

lethal girder
#

So you mean that all buttons should be in one script?

cosmic rain
#

Typically, you would have 1 purchase manager or similarly named script that would keep your gold values and the purchase logic would interact with it.

lethal girder
#

i mean like where centralizing it

cosmic rain
lethal girder
#

like this you mean?

#

and then add the .cs script as component in the empty object?

cosmic rain
#

For example, yes

lethal girder
#

Alright thanks

warm cosmos
#

I can downcast with an explicit cast in C#?

#

is there a keyword to check if a parent class variable can be downcast successfully

vestal arch
#

afaik, you should use as instead of casts for downcasting

unborn elm
lean sail
unborn elm
lean sail
# unborn elm Yeah I been working with unity on and off for 5 years now, not really the issues...

I ask because theres literally nothing unique about it. I feel like I've described it multiple times above. theres no events, no callbacks, its literally just a guarantee that a method exists. Other code outside of your interface is doing logic and checking if your classes implement the interface. If so, they call the method on the interface, and for all they know it could literally be an empty method

unborn elm
#

How does the IPointHandlers functions get called?

#

I get that the logic is not within the interface but I still think that its a very smooth way of working and therefor I wonder if anyone knows.

#

How does unity know that the interface exist on that given object!? Somehow it must either have a list of all objects impelenting it or look for them right?

unborn elm
#

Of cousre but is that how its done with IPoint interfaces? Is the eventsystem looping over all gameobjects to see if they have that particular interface?

graceful turtle
#

Hi! Does anyone know how i can handle a settings menu with netcode for GameObjects before initiating a server or join one? I'm trying to setActive(false); some buttons in the main menu when you run the game but when the function that makes the buttons not active is called it indeed deactivates the buttons but not visually only until you become a host or a client.

lean sail
#

The answer of what logic they do doesnt matter here. The simple fact of it is they call the methods directly. You cant do this in your case unless you basically recreate what a delegate is, so you might as well just stick to what you currently have

warm cosmos
#

I want to create an object that has the same settings as a component of a reference to a prefab, but this is not allowed. is there a different way to instantiate something like this?

unborn elm
# lean sail I'm not sure what unity does with their event system, or what interfaces we're e...

I think thats because you think I have a issue, I have a good alternative but still Im intressted in how unity handles interally, where it lets you implement interfaces that have functions that get triggered by events without me having to subscribe to them. I get that there are other classes that subscribe and then triggers the functions of the interfaces i just wonder how it works. Where is the logic written since it of course cant be in the interfaces? Is it the coliders that looks for. Interfaces when certain triggers such as point click are met?

#

Or is it the eventsystem that has an array of all objects impelenting the relevant interfaces?

cosmic rain
#

You can instantiate the whole object with the component if you want.

warm cosmos
cosmic rain
mellow sigil
warm cosmos
#

I dunno what cast check means

cosmic rain
unborn elm
#

And then its easy to conclude that s similar system that involved other objects isnt really viable

warm cosmos
#

(I made a spacial hash grid for fast lookups)

unborn elm
warm cosmos
#

I am using a spatial hash grid to store previously generated objects

cosmic rain
warm cosmos
#

fair enough

#

I'm doing something else illegal. I have a ScriptableObject script with a GameObject variable that I put my prefab into. This prefab has a collider2d component but it looks like only the transform component is there?

#

actually, I think I messed up - one sec

vestal arch
#

if it's a prefab you'll have to instantiate it first

#

doesn't really make sense to get the bounds of an object that doesn't exist in the scene

warm cosmos
#

it does in my case - I need to spawn a bunch of things in passes, and it's important that nothing overlaps. Since there's no actual guarantee that any spot I sample in the world can fit the object, I think it's more elegant to check the bounds first before instantiating it

vestal arch
#

oh just getting the size of the collider? misunderstood that, mb

warm cosmos
#

yeah all good, i am usually bad at making myself clear

vestal arch
#

but how are you defining the bounds as a Vector2?

warm cosmos
#

it looks like Physics2D.OverlapBox takes "size", which I think is not extents.. just the width/height

#

I'm not 100% actually

vestal arch
#

what if it isn't a boxcollider though

warm cosmos
#

any Collider2D has bounds

#

I am just taking the extents

#

I didn't actually need to downcast

vestal arch
#

i mean, if it's not a boxcollider, a boxoverlap check would be inaccurate

warm cosmos
#

I guess I still need the actual collider somehow

warm cosmos
#

Yes

unborn elm
#

Are you using polygon colliders with very custom shapes? Otherwise i think box collusions should be good enough

warm cosmos
#

I plan to hopefully get pretty precise, so ideally yes

vestal arch
#

if they have rigidbodies you could just let them overlap and fix themselves

warm cosmos
#

Not necessarily

unborn elm
#

You could also do it in two steps, first check with box and if that works spawn and check with real colliders

#

In that case it will be a fast check in 99% of the cases but with a safety for the odd cases

warm cosmos
#

I only really need to get a Collider2D in my code so I can use it to check against other colliders

vestal arch
#

(also consider if you have multiple colliders)

warm cosmos
#

true, in which case I can probably get all collider components instead

#

but I'll worry about that later

unborn elm
#

Yeah but if you need the exact collider you need to instanciete it or a proxy with the same collider

warm cosmos
#

yeah if that's the case then so be it

#

would it lead to performance issues if I instantiate a prefab and change it's position for each potential spawn point, for potentially a hundred different prefabs with thousands of locations

#

nah actually

vestal arch
#

the work would be in instantiating the prefab, and the physics check

warm cosmos
#

I can instantiate an empty gameobject with a collider with the same settings as the prefab right

#

doesn't have to include anything else

vestal arch
#

if you're using a separate prefab then that seems like a pain to deal with in the future

warm cosmos
#

well no, something like this

#

and then just delete collisionChecker when I'm done with this prefab

soft shard
vestal arch
#

or i guess always have the composite first, if you can remember that, but that sounds like a future headache

warm cosmos
#

I guess it doesn't actually matter here because all of this is done when the world is generated and only once

soft shard
# warm cosmos

Also I dont think you can do this, because Collider2D is not a component that can be added to an object on its own, whatever inherits it can (for example: BoxCollider2D), youd have to know or check the type, which may provide different properties to add... There may be a way to "clone" the component, though I cant recall the API and if its editor-only atm

soft shard
warm cosmos
#

hmm okay

#

I think I will just spawn a temporary prefab and move it around for collision checks, seems the simplest way at this point ๐Ÿ’€

graceful turtle
#

anybody know why my UI elements remain drawn even if i use the setActive(false); function?

#

I m using netcode for gameObjects

#

when i move them there are 2 images of them one where it previously was and one where i currently moved it

#

happens in Game scene

#

the buttons get deactivated in the left hierarchy but don't disappear from the screen

#

the buttons disappear if i create or join a game

#

but i want to be able to make a settings menu

#

i also tried redrawing the scene didn't workj

#

work

#

with sceneview.repainall();

past raven
#

has anyone encountered the problem with rigidbody2d's MovePosition where your character auto moves to the right

vestal arch
#

you're probably gonna have to elaborate

past raven
#

ever since i changed from transform.position = to .MovePosition

#

my guy just flies off to the right

#

maybe i should use addforce instead?

honest sky
#
  public GameObject car;
    public GameObject cameraPos;
    private float speed = 0;
    public float defaltFOV = 60, desiredFOV = 90;
    [Range (0, 50)] public float smoothTime = 8;

    private void FixedUpdate () {
        follow ();
    }

    private void follow () {
        speed = car.GetComponent<Rigidbody>().velocity.magnitude / smoothTime;
        transform.position = Vector3.Lerp (transform.position, cameraPos.transform.position ,  Time.deltaTime * speed);
        transform.LookAt (car.transform.position);
        Camera.main.fieldOfView = Mathf.Lerp (Camera.main.fieldOfView, defaltFOV, Time.deltaTime * 5);
    }```
anyone know why my car is tweaking like that
vestal arch
#

have you tried using LateUpdate instead of FixedUpdate

#

so it actually changes every frame

#

actually the background seems smooth, so maybe it's an issue with how your car is set to move

cosmic rain
inner shuttle
#

hi, im currently having an issue with my navmeshagent where in editor game testing he works perfectly fine and there is no issues. but as soon as i build the game he refuses to specifically see me, he does everything else fine but his sight mechanic wont work i have no idea why ive never had this issue when building. ive checked the console in game too but that isnt giving me any errors.

sight script - https://pastebin.com/1iTytLMY

knotty sun
inner shuttle
#

again, it works perfectly fine in the editor so im not sure what to even debug

knotty sun
#

everything

inner shuttle
#

ok?

shell mortar
#

Where can I find assets for making a small 3d horror maze game?

rigid island
#

google around.

#

asset store. etc

shell mortar
#

Iโ€™m using ChatGPT to help me make it.

rigid island
#

also GPT is not going to help you do anything but copy and paste, when something breaks. You won't know how to fix it

knotty sun
shell mortar
rigid island
wheat elbow
#

Hi all,

I switched to the new input system to tackle gamepads / controllers better. While most things are fine, I noticed two areas with issues --

  1. I have auto-swtiching on between the mouse / keyboard and the controller. It looks like using my mouse cursor is fine, but when I switch to the controller, there is some kind of strange secondary cursor that shows up. However, the mouse cursor is rendering the correct glyphs over my hotspots, but that is stationary.

I've attached a video here just in case, if that would help!

ocean hollow
#

quick question: is the resource usage of code execution in the editor when using the [ExecuteInEditMode] attribute the same as runtime?

ocean hollow
leaden ice
#

in the vast majority of cases they won't be running on the same device so it's all relative

#

plus ExecuteInEditMode works very differently from runtime in terms of how often Update runs, etc.

ocean hollow
leaden ice
leaden ice
ocean hollow
leaden ice
#

it's on their computer, or phone, or xbox or whatever

leaden ice
#

if you want to test performance you need to make a build and profile the game on the target hardware.

ocean hollow
ocean hollow
leaden ice
#

no

#

usually the build is faster

#

the editor has a lot of overhead on its own

ocean hollow
wheat elbow
# wheat elbow Hi all, I switched to the new input system to tackle gamepads / controllers be...

The other issue is -- it looks like I'm unable to click on TMP_InputFields correctly anymore.

This worked on the old input system, but I have a hunch that due to the new input system, the mouse position is somehow not being read correctly?

This doesn't work on controller, nor does it work on regular keyboard / mouse anymore.

I tried looking up this issue, but I couldn't find any threads regarding it, so I just wanted to ask here in case anyone else faced the same issue when switching over to the new input system.

Any guidance / help is appreciated, thank you!! ๐Ÿ™‚

vestal arch
#

there is a color change, which suggests it is being clicked, so maybe try listening to some events and see where it's going wrong

wheat elbow
vestal arch
#

the input debugger would let you see if the "click" action is being received correctly, but i don't think it'll help if the issue is with detecting the click on the inputfield specifically

#

so maybe try to deduce which part is going wrong (receiving the click vs selecting the inputfield) and go from there

wheat elbow
vestal arch
#

right, and also check the input debugger for the first part

ionic grove
#

Do you guys know why this wouldn't be working? My object that I have in the scene is tagged "Lever"

leaden ice
ionic grove
#

Just using a switch statement:

string colliderTag = collider.tag;

switch (colliderTag)
{
    case "Player":
        NetworkObject networkObject = collider.GetComponentInParent<NetworkObject>();

        // Punch
        PunchServerRpc(networkObject.NetworkObjectId);
        break;
    case "Lever":
leaden ice
#

Preusmably that collider is not the collider from your first screenshot

#

it's a different one

ionic grove
leaden ice
wheat elbow
ionic grove
#

I guess I can name is something more obvious to confirm

leaden ice
slow shale
#

Im making a multiplayer game with URP, i need to remove a URP camera, sadly it displays an error that says i cant remove it because universal additional camera data depends on it. Tried to remove the whole gameobject also doesnt work. Any solutions?

leaden ice
wheat elbow
slow shale
wheat elbow
leaden ice
#

Or you don't have another line of code destroying the camera component?

slow shale
#

120% sure

leaden ice
#

show the full code and full stack trace

vestal arch
slow shale
vestal arch
#

i think that's just debugging what devices are under what actions? i was wondering why it wasn't familiar

leaden ice
vestal arch
#

there should be a different one for debugging detection

wheat elbow
#

Thanks for the heads up on that front -- sorry for all the questions btw -- was relying on the old system so far, since i'm making a point-and-click game haha, but a couple of people mentioned they would like controller support / steamdeck verification, so started looking into this XD

leaden ice
wheat elbow
leaden ice
#

This part here that shows where in the code everything is happening

wheat elbow
#

oh!

#

So just the regular console?

#

(I expanded the debugs above but couldn't see anything pertaining so was just wondering)

slow shale
# leaden ice

ohhhh thats what its called? one second to export the build again just to make sure(need to run it on another client)ลพ

ionic grove
leaden ice
ionic grove
leaden ice
#

that's probably a major issue

#

if you don't fix it

#

idk

#

without knowing your code

slow shale
#

log file:
Can't remove Camera because UniversalAdditionalCameraData (Script) depends on it

#

same error in editor, didnt see it

leaden ice
#

and the stack trace...?

slow shale
#

its just : Can't remove Camera because UniversalAdditionalCameraData (Script) depends on it

leaden ice
#

that doesn't make sense if you're destroying the GameObject

knotty sun
#

the answer is obvious
destroy UniversalAdditionalCameraData first

leaden ice
#

show the full code

#

well yes you can do that^

#

but regardless the error doesn't make sense if you're destroying the GameObject

#

You probably left the other code in or something

vestal arch
#

@wheat elbow in the Input Debug menu, go to the Devices dropdown, and double-click one of the devices there
at the bottom of the new window, there should be a log of events from that device

wheat elbow
# wheat elbow

Also just updated to 3.0.9 in textmeshpro just in case, not sure if that would help -- looks like I'm still facing the same issue but hopefully being up to date helps haha.

wheat elbow
slow shale
#

i might have found the problem, testing it now, a script looks like it showed an error in editor that otherwise didnt show in the built game

#

wepon sway to be exact

wheat elbow
#

tried to click a few times just in case

#

so it seems like it's registering the lick

#

*click sorry

#

but I'm not sure if that would correspond somehow to it being correctly read into the TMP_InputField

slow shale
#

yep, that fixed it, wierdly the built game didnt show the error, although now i have a different error to fix lol

wheat elbow
#

They all seem to have similar things

slow shale
#

anyways sorry for spending your time on a dumb mistake, thank you @leaden ice โค๏ธ

wheat elbow
#

Not sure if this would help, but here's an example of one of my TMP_InputField components

#

it was working before the update, but I suspect that the cursor reading would be different, hence why it's not selecting as expected?

#

This is also my event system prefab that spawns in every scene, if that would help!

vestal arch
wheat elbow
#

Ahh ok

#

interesting

#

so when I click on it, and the cursor doesn't show up -- it does register a select AND a deselect!

But let's say I do click on it, and the cursor does show up, then it only registers a select

#

I don't understand why it's auto-deselecting, very strange

#

For reference, this is the script I attached to one of my input fields as sanity:

#
using UnityEngine;
using TMPro; // Make sure to import the TextMeshPro namespace

public class FauxScript : MonoBehaviour
{
    public TMP_InputField inputField;

    void Start()
    {
        inputField.onSelect.AddListener(OnInputFieldSelected);
        inputField.onDeselect.AddListener(OnInputFieldDeselected);
    }

    void OnInputFieldSelected(string text)
    {
        Debug.Log("Input field selected");
    }

    void OnInputFieldDeselected(string text)
    {
        Debug.Log("Input field deselected");
    }
}
#

Also when I hover over it, and even if I stay in the same position while the caret blinks, it fires a "select" AND "deselect" event.

vestal arch
#

what about the ones that are acting normal?

#

just to get a reference point

wheat elbow
# vestal arch what about the ones that are acting normal?

Strangely, it looks like none of them are after updating to the new system ๐Ÿ˜ฆ

Granted, it's not like they are fully unselectable, but the user has to move their cursor to a weird position, which seems quite inconvenient haha

#

Thankfully there aren't many places with input in my game, but yeah it seems like all of the fields have the same issue from when I tried it yesterday ๐Ÿ˜ข

vestal arch
wheat elbow
languid hollow
#

Everytime I re open my project one of my scriptable objects has this error on it. No idea why, any suggestions?

[CreateAssetMenu(fileName = "ShurikenFactory",menuName = "WeaponFactory/Shuriken")]
public class ShurikenFactory : WeaponFactory
{
public override IWeapon ProvideWeapon(IWeaponParent parent)
{
return new Shuriken(parent,data as ThrowableWeaponData);
}
}

eager yacht
#

Fix your compiler errors

languid hollow
#

there arent any

eager yacht
#

Show the console. Also is the script name the same name as ShurikenFactory? data does look to be in this script either, unless it is in an inherited one.

languid hollow
#

public abstract class WeaponFactory : ScriptableObject
{
public WeaponData data;
public abstract IWeapon ProvideWeapon(IWeaponParent parent);
}
}
Yeah data is inherited and the script names all match, if I go into the script and save any changes it works again, so its not a big deal just kinda annoying to have to do that every time I open the project

eager yacht
#

Hm, how do you make the SO?

languid hollow
#

Just through the normal Create, Weapon Factory then select Shuriken

eager yacht
#

Strange, was wondering since I've seen some "fake" compile errors when you make an SO in a scene and fail to save as an asset properly, or if the SO type is in a dll/editor folder. But if you are making it via the normal menu, then I'm not sure.

languid hollow
#

Yeah weird, whatever its not a big deal ill look into it more

somber nacelle
#

before you open the project again, check to see if the meta files for both the SO instance and the script file exist, and make sure that in the .asset file for the SO instance it shows the correct guid for the script (it will be in the m_Script property) and the script's guid will be in its meta file

languid hollow
#

fileFormatVersion: 2
guid: 2bd81912af68ff04a9139be98f025412
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

i see this in the SO asset.meta file and this in the actual cs script meta file
fileFormatVersion: 2
guid: d952149306f44165a51a1a32a0101f8b
timeCreated: 1730501946

#

are the guids supposed to be matching?

somber nacelle
tacit talon
#

I tried doing it this way, and I quickly found out that the angle difference I get is completely useless, because all local rotations change in unpredictable ways (due to transform.LookAt()) making it impossible to infer any kind of angle difference between two joints directly.
What I ended up doing was to create a triangle of the positions of the joint, its end-effector, and its parent and then comparing the angle at the joint on both rigs. So, basically your method A twice and then compare the results.

swift falcon
#

can someone help me? im making an gorillatag fangame and its not building anymore

#

i already reinstalled photon vr but nothing works

knotty sun
#

why do you have Photon in a resources folder?

swift falcon
#

its got installed there

knotty sun
#

then maybe you should ask Photon why they do that if it will not build

warm cosmos
#

I don't know why this wouldn't work but

#

IsTouching is not true for these two colliders

#

am i missing something?

cosmic rain
warm cosmos
#

I found this page before but it's not super descriptive

#

originally I thought it was because isTouching was returning false always because there hasn't been a physics update yet

#

but here I am putting it in FixedUpdate() which means there should have been a physics update

lean sail
warm cosmos
#

oh yeah I read that too, but there's nothing it in that implies what i'm doing will not work

#

...as far as I can tell

cosmic rain
lean sail
#

does it always return false, for more than 1 fixed update?

warm cosmos
#

yes, I put a breakpoint in the debug log too and it's never hit

knotty sun
#

maybe play with the ContactFilter2D overload to see if you can get any contacts

bold wraith
#

I continue to have nav mesh problems in the unity asset game creators.

#

Does anyone know how to solve this aside?

#

!code

tawny elkBOT
bold wraith
knotty sun
# bold wraith

that looks so wrong.
It's defining the same class twice in the same namespace and the comma at the end of line 21 makes no sense

bold wraith
#

I know I was altering it around, and the concept of it continued to halt me of starting my project with the provider.

warm cosmos
#

ah, I see a forum post that says that for 2d the physics engine only cares about collisions between a rigidbody and other things?

vestal arch
warm cosmos
#

alright, looks like I can't use colliders at all for spawning things then

#

wow

vestal arch
#

you do need a collider as well

#

the rigidbody handles physics, the collider defines the bounds of the object

#

they work together

warm cosmos
#

yeah I get it now

#

if I need to wait for physics updates to check if something overlaps then it's not the correct approach for me

vestal arch
#

you don't though, you can use casts to check for colliders

cosmic rain
#

Colliders without rb secretly belong to one hidden static rb actually.

vestal arch
cosmic rain
#

Yeah. It might be an overstatement, but iirc that's how the physics system treats them under the hood.

warm cosmos
cosmic rain
#

Casts and overlaps. I think that has been suggested many times to them...

warm cosmos
#

you're prolly right, I'm just confusing myself by trying to do use many new concepts at once

#

so thanks for being patient

vestal arch
# warm cosmos

have you checked that their layers are allowed to touch, they have rigidbodies, etc?

#

and if there's multiple colliders where you might be getting the wrong one

#

but if they're simple you could use casts instead which do the checking when theyre called

warm cosmos
#

so a BoxCast doesn't need physics updates to find colliders?

vestal arch
#

yeah

warm cosmos
#

do my prefabs also need a rigidbody for the BoxCast

vestal arch
#

A BoxCast is conceptually like dragging a box through the Scene in a particular direction. Any object making contact with the box can be detected and reported.

vestal arch
warm cosmos
#

hm I see

#

okay, this will probably work, thank you

knotty sun
maiden heath
#

Difference between radius and maxHeight? I don't get it

#

Doesn't SphereCast just make an invisible sphere and if it collides with something, return that info to hitInfo? What do we need a maxHeight for?

mellow sigil
#

There's no maxHeight. Do you mean maxDistance?

maiden heath
mellow sigil
#

Spherecast makes an invisible sphere and moves it towards direction, like throwing a ball

maiden fractal
#

You are confusing with CheckSphere

thin aurora
#

The radius parameter is the size of the sphere. The maxDistance parameter is how far the sphere should travel in the given direction.

maiden heath
mellow sigil
#

Do you know what it does in normal raycast?

thin aurora
mellow sigil
#

It's the same thing here

thin aurora
#

By default this is basically infinite

maiden heath
thin aurora
thin aurora
#

IDK how it would respond to negative distance

maiden heath
#

Okay I think I get it now

#

Thx

inner latch
#

I'm making a player controller and the player walks fine when walking backwards but barely moves when trying to walk forwards. Could anybody help? (video attached for reference)

knotty sun
tawny elkBOT
inner latch
vestal arch
#

why the * Application.targetFrameRate?

inner latch
#

to correct the time.deltatime

vestal arch
#

yeah it's basically just 1 then

inner latch
#

yeah

knotty sun
vestal arch
#

it's negating the effects of using deltaTime to begin with

#

physics stuff should probably be in FixedUpdate anyways

knotty sun
vestal arch
knotty sun
#
       moveInputVector = new(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));

        mouseInputVector = new(-Input.GetAxisRaw("Mouse Y"), Input.GetAxisRaw("Mouse X"), 0);
vestal arch
#

those are separate vectors

knotty sun
#

my bad

vestal arch
inner latch
#

it's there so I can cap it and all that through code

#

and rb drag is janky imo

vestal arch
#

make sure your input axes are correct, try logging moveInputVector to see if it's what you expect, just to narrow it down to either the input or the physics

ocean hollow
#

what could be causing neither of my debugs to print? i have the script and a capsule collider on the same object but nothing pops up in the console

    {
        if (other.CompareTag("PlayerTrigger"))
        {
            print("In range of player and attacking");
            animator.SetTrigger("Hit1");
        }
        else
        {
            print("Not in player trigger");
        }
    }```
knotty sun
#

the method is not being executed

ocean hollow
knotty sun
#

missing rigidbody, colliders not marked as triggers, lots of other things

ocean hollow
#

oh, i forgot the rb... thanks

hexed pecan
elfin tree
#

I draw a ray from my main camera to my mouse position like so

var ray = Camera.main.ScreenPointToRay(Input.mousePosition);

But for some reason, the ray.origin keeps changing, even though the camera does not move, what am I missing?

vestal arch
#

it's not a ray from the camera to the mouse, it's a ray from the mouse through the camera into the scene

#

the ray.origin is just where you clicked

elfin tree
vestal arch
#

no, the camera position isn't really relevant to the ray

#

the camera just provides a screen, the screen is then mapped into the world

#

the ray is orthogonal to the plane of the screen

elfin tree
#

ah I think that's what's wrong then, I'm trying to use ray origin and hit to determine which object should be selected, but i should probably use distance from camera after the raycast logic instead?

vestal arch
#

what?

#

what are you trying to do?

#

what's the actual issue?

elfin tree
#

object selection

vestal arch
#

ok, so just use the first hit?

elfin tree
vestal arch
rain minnow
vestal arch
rain minnow
#

If you're not using colliders, then you need to check the distance between each object and the camera . . .

elfin tree
#

yeah it's something using the mesh

#

i think the simplest thing for now is to keep using the whole "ray on mesh" thing but disregard distance from it to decide which object to select, just go through all the objects hit by the ray and calculate distance from camera to determine which one to select

vestal arch
#

the simplest thing would probably to use colliders, no?

elfin tree
warm cosmos
#

I'm back again. although a BoxCast or CircleCast can check against colliders, it looks like right now that it won't check against a collider's new position if I change it (and there hasn't been a physics update yet).

somber nacelle
#

you can call the SyncTransforms method, though be aware that method can be costly depending on the number of physics objects in the scene

#

otherwise, yes you are querying the current state of physics which means anything moved since the last fixedupdate will not have updated in physics yet

warm cosmos
#

I see... I would probably have to call it n times for n objects

#

because I'm placing the whole world's stuff one by one

leaden ice
#

you just need to call it once after all the things move

#

but hwat are you actually doing here?

warm cosmos
#

I'm procedurally generating everything in the entire world

leaden ice
#

If this is just some grid based thing, you shouldn't use physics at all

warm cosmos
#

it's not grid based

#

it's like this: I have a list of prefabs and some spawn conditions

  1. for each prefab, generate a poisson disk sample
  2. spawn the prefab at the sample points ONLY IF it doesn't collide with something already spawned
leaden ice
#

if you're using poisson disk you don't need physics

#

that's what poisson disk is for

warm cosmos
#

yes, but I have multiple passes

leaden ice
#

save the results of earlier passes

#

use a single poisson disc arrangement for all passes

warm cosmos
#

it's not obvious how I can use a single arrangement

#

my objects all have different densities based on location and whatnot

leaden ice
#

do they have different sizes though

warm cosmos
#

yes

#

I'm spawning everything, that means trees, rocks, big structures, small flowers, I need the flexibility

leaden ice
#

I would probably do something along the lines of:

  • Generate the poisson discs at a high resolution
    for each object layer:
    • generate random spawn positions
    • snap them to the nearest poisson disc
    • mark all overlapped poisson discs as occupied

For later layers if you try to spawn something and it overlaps an occupied poisson disc, just don't spawn it.

#

kind of inspired by the way mapmagic does things

warm cosmos
#

let me take a look at this

#

but I think it's hard for me

#

actually.. hm.

#

you mean I should check against all the previous poisson discs if it overlaps them? that sounds expensive

leaden ice
#

Not all the previous discs

#

You would use an interval tree to make that fast

warm cosmos
#

another alternative I think is to use a spatial hash grid and use a custom boundary implementation that doesn't need to interact with the physics layer (which would prevent lots of expensive calls to SyncTransforms)

#

I'll sleep on it notlikethis

glass rivet
#

GetComponentInParent does'nt work๐Ÿฅบ

leaden ice
pure ore
#

Can someone help me? IT seems like my character moves for a couple miliseconds after I released the input

    private void GetMovementInput()
    {
        float x = PlayerInput.MoveX();
        float y = PlayerInput.MoveY();
        IsRunning = MovementInput.y > 0.0f && PlayerInput.Run();
        CurrentSpeed = !IsRunning ? m_MoveSpeed : m_RunSpeed;
        m_MovementInput = new Vector2(x, y);
        if (MovementInput.magnitude > 1f || MovementInput.magnitude < -1f)
            m_MovementInput.Normalize();
        CurrentSpeed *= 0.1f;
    }

    private void UpdatePlayerMovement(Transform transform)
    {
        if (m_CharacterController.enabled)
        {
            Vector3 vector = transform.right * MovementInput.x + transform.forward * MovementInput.y;
            m_MovementDirection.x = vector.x;
            m_MovementDirection.z = vector.z;
            if (MovementDirection.x > 1f)
                m_MovementDirection.x = 1f;
            if (MovementDirection.x < -1f)
                m_MovementDirection.x = -1f;
            if (MovementDirection.z > 1f)
                m_MovementDirection.z = 1f;
            if (MovementDirection.z < -1f)
                m_MovementDirection.z = -1f;
            m_MovementDirection = MovementDirection.normalized * CurrentSpeed;
            bool flag = false;
            if (m_ActiveGravity <= 0.0f && m_CharacterController.isGrounded)
            {
                m_ActiveGravity = 0.0f;
                m_MovementDirection.y = -0.27f;
            }
            else
            {
                m_ActiveGravity -= m_Gravity;
                m_MovementDirection.y = m_ActiveGravity;
            }
            CollisionFlags collisionFlags = m_CharacterController.Move(MovementDirection);
            if (collisionFlags == CollisionFlags.Above && m_ActiveGravity > 0.0f)
                collisionFlags = m_CharacterController.Move(Vector3.up * -0.01f);
        }
    }
}
leaden ice
#

probably it's coming from there

pure ore
# leaden ice Depends on how this works:` PlayerInput.MoveX();`
public class PlayerInput
{
    public static float Sensitivity = 1f;
    public static bool HasController { get; private set; }
    public static bool IsInverted;
    public static float MoveX() => GetInput(GamepadInput.GetAxis(InputControlType.LeftStickX), Input.GetAxis("Horizontal"));
    public static float MoveY() => GetInput(GamepadInput.GetAxis(InputControlType.LeftStickY), Input.GetAxis("Vertical"));

    private static T GetInput<T>(T inputKeyboard, T inputGamepad)
    {
        T obj = default(T);
        if (!inputGamepad.Equals(default(T)))
        {
            HasController = true;
            return inputGamepad;
        }
        if (!inputKeyboard.Equals(default(T)))
        {
            HasController = false;
            return inputKeyboard;
        }
        return obj;
    }
}
#

Do you see anything wrong? Genuine question

leaden ice
#

GetAxis has smoothing built into it

#

Use GetAxisRaw if you don't want that

pure ore
#

Oh okay, I see

knotty sun
#

why do you go to all the trouble of calculating m_MovementDirection and then not use it?

pure ore
#

I do use it, I just had to cut it off because discord said the code was bigger then the word limit

knotty sun
#

then use a paste site to post code correctly. but you controller.move does not use it

pure ore
#

see? ```cs
private void UpdatePlayerMovement(Transform transform)
{
if (m_CharacterController.enabled)
{
Vector3 vector = transform.right * MovementInput.x + transform.forward * MovementInput.y;
m_MovementDirection.x = vector.x;
m_MovementDirection.z = vector.z;
if (MovementDirection.x > 1f)
m_MovementDirection.x = 1f;
if (MovementDirection.x < -1f)
m_MovementDirection.x = -1f;
if (MovementDirection.z > 1f)
m_MovementDirection.z = 1f;
if (MovementDirection.z < -1f)
m_MovementDirection.z = -1f;
m_MovementDirection = MovementDirection.normalized * CurrentSpeed;
bool flag = false;
if (m_ActiveGravity <= 0.0f && m_CharacterController.isGrounded)
{
m_ActiveGravity = 0.0f;
m_MovementDirection.y = -0.27f;
}
else
{
m_ActiveGravity -= m_Gravity;
m_MovementDirection.y = m_ActiveGravity;
}
CollisionFlags collisionFlags = m_CharacterController.Move(MovementDirection);
if (collisionFlags == CollisionFlags.Above && m_ActiveGravity > 0.0f)
collisionFlags = m_CharacterController.Move(Vector3.up * -0.01f);
}
}

knotty sun
#

and you use it there where?

pure ore
#

I declare a public Vector3 MovementDirection that points to m_MovementDirection

#
    [Header("Movement")]
    private CharacterController m_CharacterController;
    public float m_MoveSpeed = 0.5f;
    public float m_RunSpeed = 1f;
    public bool IsRunning { get; private set; }
    public float CurrentSpeed { get; private set; }
    [SerializeField] private Vector2 m_MovementInput;
    [SerializeField] private Vector3 m_MovementDirection;
    [SerializeField] private float m_ActiveGravity;
    [SerializeField] private float m_Gravity = 0.02f;
    public Vector2 MovementInput => m_MovementInput;
    public Vector3 MovementDirection => m_MovementDirection;
knotty sun
#

which you conviently do not show, hence the need to use a paste site

pure ore
#

Oh yeah, pastebin doesn't have a limit, does it?

knotty sun
#

no idea, you're the one pasting code

tawdry jasper
#

I'm using an asset pack that has different material variants for different faces. I want to make a generic script I can put on my objects to "animate" the faces by switching materials but I don't want to assign them all for each object. So I want something like "static" Meterial references in my script. I can't assign them in the inspector. How would you do it? (I can introduce a "manager object" that has the material assigned and reference that, or I could initialize the static vars via code (I'd hardcode the paths to the materials - do I need them in the resources folder for that?)

leaden ice
#

create one instance of it

#

and have all the scripts point to that one SO

young tapir
#

Would this be a good or "bad" method of creating inputs? I'd like to have an expandable method but I'm not sure if this is taboo

#

I did just try a dictionary to store a string and Key but apparently Unity doesn't serialize dictionaries

knotty sun
#

looks ok but are you sure you want GetKey and to allow multiple keys?

leaden ice
young tapir
#

Ah good point actually, I did know about that angry_laugh_cry

young tapir
knotty sun
young tapir
#

That is what I want blobnod

knotty sun
#

that will be adding a lot of force over a very small time period

leaden ice
#

It's fine if you're looking for a continuous acceleration - e.g. a rocket engine

young tapir
#

Motion seems to be smooth and steady at 10 on the z axis, I can cross a 100m plane in 10 seconds which is what I'm aiming for

#

I think I see the problem with jumping lmao

knotty sun
#

As you are using GetKey and are happy about that then you can probably move the whole code to FixedUpdate, it's actually not a bad solution in all

vestal arch
young tapir
#

Yup, I set up two lists for different inputs, should be able to add mouse and single use things to the singleInput list nodcat

vestal arch
#

though you'll need to use Update for GetKeyDown since inputs are bound to that

#

with GetKey since it's a continuous action it'll work fine in FixedUpdate, but GetKeyDown will be true for 1 frame, so that won't handle correctly in FixedUpdate

leaden ice
#

indeed - really you should handle input in Update

#

and physics in FixedUpdate

young tapir
leaden ice
#

well sorry

#

you mean a one-off impulse force/

#

Yeah that will be ok in Update

young tapir
#

Ya

#

It worked pretty nicely, I am surprised how simple a character controller is. A few months ago I would've spent a few hours on this ๐Ÿ˜

knotty sun
leaden ice
#

how simple a character controller is
Ehhhh it's simple to get something working but it's generally complicated overall

#

wait till you want to enforce a max speed, or handle crouching, or a million other things

sleek heath
#

or smoothing

knotty sun
#

@young tapir But anyway, don't listen to us old farts. 10/10 for effort

pure ore
#

How can I do math on this so its kinda like a deadzone? The more you go, the faster you get? And then when you let go of the joystick, it resets?

public static float LookX() => GetInput(GamepadInput.GetAxis(InputControlType.RightStickX), Input.GetAxis("Mouse X"));
public void GetInput()
    {
        m_MouseX = PlayerInput.LookX() * PlayerInput.Sensitivity;
        m_MouseY = PlayerInput.LookY() * PlayerInput.Sensitivity;
    }

    public void Rotation(Transform character, Transform camera)
    {
        m_CharacterRotation *= Quaternion.Euler(0.0f, m_MouseX, 0.0f);
        if (m_UseHorizontalRotation)
            m_CharacterRotation = ClampRotationYAxis(m_CharacterRotation, -m_HorizontalRotationValue, m_HorizontalRotationValue);
        character.localRotation = m_CharacterRotation;

        if (camera)
        {
            m_CameraRotation *= Quaternion.Euler(m_MouseY, 0.0f, 0.0f);
            if (m_UseVerticalRotation)
                m_CameraRotation = ClampRotationXAxis(m_CameraRotation, -m_VerticalRotationValue, m_VerticalRotationValue);
            camera.localRotation = m_CameraRotation;
            Vector3 localEulerAngles = camera.localEulerAngles;
            localEulerAngles.z = 0.0f;
            camera.localEulerAngles = localEulerAngles;
        }
        LockCursor();
    }
#

I just want it for the rightstick though, not the mouse

sleek heath
candid hamlet
#

HI! I would like to ask some help. If I have elements in a list. I create an instance from every list element using a prefab. How can I find the i element prefab from the list. For example I am searching the third prefab? Thanks a lot

leaden ice
#

Are there multiple prefabs? Your question is confusing.

candid hamlet
#

nope. For inventory system. I store the items in a list, and I draw a gameobject prefan on the canvas. I am searching the third item on the canvas

knotty sun
#

the third item in a List is index 2

candid hamlet
#

I attached a prefab for every element and I stored them in an Item type list

knotty sun
#

what do you not understand about what I said?

leaden ice
#

you need to be precise with your language here. The things you create with Instantiate are not prefabs

#

the source object is a prefab

#

the thing it creates is an instance of the prefab

candid hamlet
#

the yellow one is the prefab for the sword, If I attach it, it working, but I need to delete the prefab from the right side as well to delete in from the list

leaden ice
#

prefabs are assets that live in the project window

#

they do not live in a scene

candid hamlet
#

as it is in beta state, I am used a rectangle with an Image, and saved it as a prefab

leaden ice
#

you might have saved it as a prefab

#

but the thing in the scene is not a prefab

#

it might be an instance of the prefab

candid hamlet
#

yes, it is an instance from the saved prefab

#

but how can I find the third, or the first one to delete it?

leaden ice
#

just access it from the list

#

list[2] is the third element

#

(with list[0] being the first)

candid hamlet
#

in the list, yes. But I created an instance for list[2] on the canvas. How can I find the instance ?

knotty sun
#

it's the same thing, they are references

leaden ice
#

in a variable, or in another list, for example

#

or a Dictionary

knotty sun
#

in the List ?

leaden ice
#

or wherever

#

Instantiate returns the object it created

#

so you need to make sure you save the result of Instantiate somewhere if you mean to use it again later.

candid hamlet
#

here is the code

leaden ice
#

What is itemsDisplayed

candid hamlet
#

if I equip the 2nd item from ItemsDisplayed I need to delete the instance from the screen

leaden ice
#

what is inventory.Container storing

#

It looks lioke you're storing a reference to the instance in ItemsDisplayed

candid hamlet
#

itemsdisplayed contains the inventory elements

leaden ice
#

you can and should just get it out of there

leaden ice
#

you have to understand we have no context whatsoever about what you're doing here

candid hamlet
#

if I am using the destroy command and try to pass the itemsdisplayed[2], it not works

leaden ice
#

it appears to be a dictionary

#

and the key is... I don't know. Whatever inventory.Container[i] is

#

so that is the same key you need to retrieve the object

#

but this is missing a lot of context for us, so it's hard to say exactly what anything is.

knotty sun
#

how come you are asking about Lists when you are actually using a Dictionary?

candid hamlet
#

this is it

leaden ice
#

See how it's a dictionary

#

If you did ItemsDisplayed[x] = y; then if you want to get y back out, you do var y = ItemsDisplayed[x];

candid hamlet
#

yes , for the UI it is a dictionary

leaden ice
#

or equally, if you did ItemsDisplayed.Add(x, y) then you get y back with ItemsDisplayed[x]

candid hamlet
#

so destroy(ItemsDisplayed[x]) ?

leaden ice
candid hamlet
#

I will try

leaden ice
# candid hamlet

in your code it's the particular element of Inventory.Container that you added it with

candid hamlet
#

thanks

knotty sun
candid hamlet
#

yes I understand. Bu I have no clue how to delete the instance from the canvas

#

that was the question

#

I will try destroy(ItemsDisplayed[x])

wheat elbow
#

pasted in wrong channel again sorry -- keep forgetting about the input-system channel haha

leaden ice
knotty sun
leaden ice
#

Step 1. Get the reference
Step 2. Call Destroy on it

candid hamlet
leaden ice
#

you retrieve it from the dictionary

#

which is where you stored it

knotty sun
#

because you need the Key of the Dictionary that corresponds to the Value you want

candid hamlet
#

but I read, the dictionary in not an ordered list

leaden ice
#

noi it is not orderd

#

you use the key you stored it with

candid hamlet
#

key X can be anywhere

leaden ice
#

wdym "anywhere"

#

the values correspond with the exact keys you gave

candid hamlet
#

the key is unique, right? just as in SQL?

knotty sun
#

which is why I asked if you understood your code which, apparently, you do not

leaden ice
#

yes the key is unique

#

it's weird to invoke SQL here

#

but sure you can think of the dictioanry key as a database key I guess

#

in SQL the key is part of the row you retrieve

#

here you are mapping one object to a completely different object

candid hamlet
#

if I solved the destroy issue, I need to save the inventory in an SQL database

leaden ice
#

don't worry about that

#

completely different problem

candid hamlet
#

this is why I used a dictionary. Probably just to save the key

#

but thats the second part

leaden ice
#

I think one huge problem you have here is your inventory and everything is tightly coupled to the GameObject system

#

so that second part is really going to require you to completely rearchitect this whole thing

#

but we're digressing

knotty sun
#

when you use a Key you need to have the logic to recreate it otherwise you are just going to have to serial read the Dictionary, like you would a table from a database

leaden ice
#

i mean isn't the second element just the second thing in Inventory.Container here?

#

i.e. Inventory.Container[2]

#

if you want the third elemnt, use that as the key^

#

but you would definitely not be hardcoding any numbers here

candid hamlet
#

as the player pick up the items from the ground, it will appear in the itemsDisplayed Dictionary

#

than I can equip it to the caracter

knotty sun
#

you are missing the whole point, do not confuse what is happening with the data

#

unlikely to find that here try !collab

tawny elkBOT
#

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
โ€ข Collaboration & Jobs

knotty sun
#

that is what the collab link is for

spare dome
#

you would have to explain what you mean by "need help with scripts" for anyone to even say yes anyway

#

but if you are looking to collab with someone use the link

#

if you need technical help please find a relative channel to use

#

well you have yet to have said anything about what you want us to hep you with, also yes this is a unity server we talk about C# here as well

#

if you want people to collab with you and to actually help you with your project us the link, as that is what it is used for

#

ask your question here

#

or in a relative channel

#

literally ask your question

#

no, if its only 1 problem with your script like an error or something you do not get, ask it here, if you need volunteers (as you said here #archived-code-general message ) to help you please use the link as that is what it is for

#

we do not do collaboration posts here, this is what the discussion forum is for

#

what do you mean?

knotty sun
#

no, because you are not listening

spare dome
#

oh okay their messages just got deleted, was that Danny?

knotty sun
#

I think OP self. Typical over entitlement, you should just do what I want

rugged fulcrum
#

Hi, does anyone have some resources on mesh generation using a compute shader, I want to generate a mesh with a dynamic number of vertices (that isnt known at compile time) and i'm wondering how to do that, as all the tutorials i could find on it assume it operates on an existing mesh and deforms it, but doesn't generate new vertices.

storm wolf
#

Hi, I am running a few small tasks at the same time


while(!done)
  await Awaitable.EndOfFrameAsync();

essentially that block is waiting on lets say 3-6 objects at the same time. Is this bad for performance? Or would this not really affect it too much until theres hundreds of them runnning or even more?

leaden ice
#

unless you're doing some special rendering thing

#

as for performance it's similar to running 3-6 updates

#

not a big deal

storm wolf
#

okay cool thanks

#

will switch to that

warm cosmos
#

is there a way to allow polymorphism in a list exposed in the inspector?

mossy snow
#

if the contents of the list isn't MonoBehaviour-derived, the easiest way is ScriptableObjects. Second easiest way is something like odin serializer. Third easiest way is SerializeReference, assuming the list contents aren't UnityEngine.Objects of some sort

#

actually I'm not sure about the third thing for a list specifically, I've used it for single fields directly only

warm cosmos
#

different question - is there a way to draw multiple lines for a single gameobject?

#

I tried using LineRenderer but it only seems to be able to draw one line at a time

#

this is just for in-editor stuff to help me debug things

#

although I'd hope to be able to draw lines in-game too

modern grotto
#

Hello!
Would anyone help me figure out why these errors are occuring?
They ALWAYS occur when I exit play mode, and some times they start during play mode. The same errors keep appearing thousands of times

crude mortar
#

have you actually set the value in the inspector?

keen cliff
slow delta
#

cleared out my mess of code so I don't derail, got my issue sorted ๐Ÿ‘‹

cosmic rain
modern grotto
hot yacht
#

hy all i have an issue when making a HTTP Request in unity
i make this a standartd HTTP request call like this
Updated Code
https://hatebin.com/hsthbbbgcm

i dont know why, but the result is empty and yet i when tried on postman the result is not empty

grizzled dune
#

hello everyone, I just started a new project and for some reason i get these errors even though i have not even scripted anything yet

hot yacht
# grizzled dune

have you tried to regenerate project? seems like you have a missing packages

grizzled dune
#

i don't have that, all i have is this

sleek heath
#

it looks like 2018 or something

grizzled dune
#

old but its the one i used to enjoy working on a lot

sleek heath
#

I think it's time to update...

grizzled dune
# sleek heath I think it's time to update...

I already to have 2021.3, but the project im making i used to make it before with the same version 2019.1, but since i don't like to take risks even though update would be better i stick with the same version that i used to work on

mellow sigil
#

Collab doesn't exist anymore. You'll have to remove the package.

sleek heath
#

a lot of things don't exist anymore

sudden lantern
#

I have a target search with SphereCastAll using a "Homing" layer. The target is a separate object in the prefab. Question: why the hell does this method hit the enemy and not even its collider, but the parent object with Rigidbody (the collider is in the enemy parent on different object)? The enemy has a different layer than the one specified in the code

RaycastHit[] targetsInRange = Physics.SphereCastAll(origin, radius, dir, maxDistance, 
                param.GetParameter<LayerMask>(Homing_Mask), QueryTriggerInteraction.Collide);
#

This is what "Homing_Mask" parameter contains

grizzled dune
wicked scroll
sudden lantern
sudden lantern
wicked scroll
#

good, cause anything else wouldn't make any sense

sudden lantern
#

what should I do

wicked scroll
#

Here's what I'm imagining:

  1. you have a child with the layer you are querying
  2. you have a parent on a different layer
  3. when you do your physics query, it hits the child collider
    3a) BUT as far as the physics engine is concerned, that collider is 'owned' by the parent on the different layer, so that's the entity that is returned by the collision query

does that make sense?

wicked scroll
# sudden lantern what should I do

hard to say without knowing what you are trying to accomplish, but if you add a rigidbody to the child which you want to query directly, you should then be able to

sudden lantern
wicked scroll
#

think of each rigidbody as 'owning' any child colliders under it -- they all point to it as the thing that is being collided with when any of them are touched

#

so if you want each collider to be its own fully independent physics object, it needs an RB

#

generally though, I would take advantage of that since it's often what you want

#

if something hits some npc or whatever, you don't want to get its child object with the collider on it, you want the wrapper for the whole npc

hot yacht
#

Unity Web Request

upper pilot
#

I had a bug(obviously) ๐Ÿ˜›

round violet
#

i tried various things but i cant find a proper way to toggle ragdoll physics on a character using a character controller with a animation controller

leaden ice
prime lintel
#

Hi all, if I wished to implement this class as a template/generic type where it may either be int or float, how would I go about doing it? Should I simply make 2 variations or perhaps some sort of interface or generic? Thanks in advance

namespace Commons
{
    public class PropertySet
    {
        public float min {  get; private set; }
        public float max { get; private set; }
        public float cur { get; private set; }

        public UnityAction<float> OnPassedUpperThreshold;
        public UnityAction<float> OnPassedLowerThreshold;

        public void RaiseEventPassedUpperThreshold(float n)
        {
            OnPassedUpperThreshold?.Invoke(n);
        }

        public void RaiseEventPassedLowerThreshold(float n)
        {
            OnPassedLowerThreshold?.Invoke(n);
        }

        public void Increment(float val)
        {
            var overflow = val + cur - max;
            cur = Mathf.Clamp(val, min, max);
            if (overflow > 0) 
                RaiseEventPassedUpperThreshold(overflow);
        }

        public void Decrement(float val)
        {
            var overflow = cur - val;
            cur = Mathf.Clamp(val, min, max);
            if (overflow < min)
            {
                var total = 0f;
                if (overflow < 0)
                {
                    total += Mathf.Abs(overflow);
                    total += min - 1;
                }
                else
                    total = overflow;
                RaiseEventPassedLowerThreshold(total);
            }
        }
    }
}
steady moat
thick terrace
prime lintel
#

Would an interface or factory of some sort be a viable solution to having types for this class?

steady moat
#

Personally, I would just rewrite most of the function by hand or cast things to a common type.

prime lintel
#

I see, thank you

steady moat
sleek heath
#

why doesn't Unity update the .NET version? It's incredibly old

thick terrace
steady moat
somber nacelle
sleek heath
#

yay! C#11 or 12!

thick terrace
somber nacelle
# sleek heath yay! C#11 or 12!

actually we'll get at least c# 13, they plan to release on whatever is the latest supported version at the time of release and 13 just released a month or so ago

sleek heath
#

and switching from mono is a HUGE leap forward

clear basin
#

Hi there
I made an animation in which my player's model moves up. On the last frame it starts an event that calls a function which should move player's parent object to the model. However i don't know how to implement it.
I get the model's position with its spine bone, In hierarchy it looks like Player (parent ) -> player model -> armature -> spine

ocean lava
#

Can I share my movement code here?

#

I need help fixing it

leaden ice
tawny elkBOT
ocean lava
#

!code

tawny elkBOT
ocean lava
#

Discord isn't letting me send it so can I send it as a screenshot

vestal arch
#

please don't

#

wdym by discord isn't letting you send it

ocean lava
#

"You are over the message limit"

clear basin
ocean lava
#

I don't have discord pro

#

I can't get on links because of my family safety settings.
I'm legit in my late teens and my parents still won't let me get on sites without them rigourously searching through them beforehand.

#

So uh...
Guess i'm cooked.

clear basin
#

can you ask your parents to let you open the link at least just for now?

ocean lava
#

Lemme check.

ocean lava
clear basin
#

now you should find a way to access any of those links to send us your code

sleek heath
#

it's just a text editor, so it should be fine

dire crown
#

This is quite an usual issue, but I just can't find a way to fix it reliably. I've got a camera that I move in late update and for some reason, there's visual stuttering.

#

When I was first coding it it didn't happen, but after closing and reopening the project it started happening again. I have to say that what Im doing in late update is an origin shift, but it all happens at the same time by using an event

hexed pecan
#

Make sure your camera code runs after everything else

#

Lots of possible causes for stuttering though

latent latch
#

cinemachine provides some options if you're not using it

#

specifically allowing you change rendering ordering on the fly

dire crown
#

Thank you, it was indeed execution order

#

I forgot that previously I was running both at update, and luckly it fell in the right place, but when moving it to late update it was actually showing the visual stutter

#

I just had to make sure that after doing the origin shift, force a camera update

leaden ice
modern creek
#

Googlefu failing. What's that secret key combo to change the editor camera pan speed?

#

It's something weird like holding right mouse button and scroll wheel up/down..?

modern creek
#

Oh, that was exactly it lol.. thought I tried that..

leaden ice
#

check "flythrough mode" in the doc here^

#

Or sorry - "Change the move speed of the camera"

modern creek
#

As an aside, is there a way to make it "consistent"? It seems to be float based, so moving the scene around the origin is slow, but at larger manhattan distances it scrolls fast

leaden ice
#

with F or double clcik

modern creek
#

hm.. I'll keep playing with it.. just navigating around the origin seems to be really fiddly and inconsistent

#

i set the pan speed to 1.36x and pan, then do something, then try to pan again and it's very slow (even though it's still at 1.36x)

#

not sure I understand what's going on under the hood

nova leaf
#

what would be the best enemy detection for an rts? overlap shere? trigger collider? global list of enemies and checking which one is in range? or something else?

lean sail
thick terrace
nova leaf
#

i am using overlap shere rn, i just get lagspikes every time the script goes through the detected enemies to check which one is the closest (the units have turrets, and the enemy detection is on the parent, but every turret checks for the closest enemy.. because yk, the turrets are a little to sometimes far apart and have their own range)

rugged fulcrum
#

danger hehe~

lean sail
#

Also deep profiler can tell you more about where the lag is coming from

nova leaf
nova leaf
# lean sail Maybe share the code then, but if you're doing this all at once on like 1000 uni...
void EnemyDetection()
{
    timer += Time.deltaTime;
    if (timer >= 0.5f)
    {

    Transform nearestEnemy = null;
    float nearestDistance = float.MaxValue;

    foreach (Transform enemy in unit.EnemiesInRange)
    {
        float distance = Vector3.Distance(transform.position, enemy.position);
        
        if (distance > DetectionRange || !IsEnemyInSight(enemy))
        {
            continue;
        }
        else
        {
            if (distance < nearestDistance)
            {
                nearestDistance = distance;
                nearestEnemy = enemy;
            }
        }
    
    }

    if (nearestEnemy != null)
    {
        target = nearestEnemy;
    }
        timer = 0;
        }
}
#

that's on every gun/turret on each unit

lean sail
#

One thing u could do is get the sqrMagnitude because you dont need the actual distance here

thick terrace
#

what's EnemiesInRange , is it just a list?

nova leaf
thick terrace
#

may be worth looking at IsEnemyInSight too

nova leaf
#

thats why i cant use the same code for all

thick terrace
#

but if you can't get it any faster you could start looking at ways to run less stuff per frame, either don't update every turret every frame, or break up this logic so you can run it across multiple frames

nova leaf
lean sail
#

Like how many units have this script even

thick terrace
# nova leaf it's every 0.5 seconds

you could try turning it into a coroutine then, you could yield every x number of iterations so it's only doing so many raycasts per frame

nova leaf
wicked scroll
nova leaf
wicked scroll
#

is it a micro optimization, but if you're calling it constantly it might matter. I donno how it would be no better though unless the compiler is smarter than I think

nova leaf
#

hmmm i will try

thick terrace
#

it can't hurt if you're doing it a lot, but yeah it's probably not the main problem

lean sail
#

deep profiler

nova leaf
wicked scroll
#

if the problem is spikes, you might have better luck actively maintaining this list per turret instead of refreshing it every time

#

there are other tricks too depending on what your game is. are your enemies following set paths where you can know which enemy is furthest along the path, and therefore closest to the next turret? that kind of thing

nova leaf
wicked scroll
#

but yes, do some profiling rather than random stuff

wicked scroll
lean sail
#

That is really hard to phrase lol I hope it makes sense, I'm on mobile or I'd type it out

nova leaf
#

i will write that down and try all your suggestions๐Ÿ‘๐Ÿป

rugged fulcrum
#

Hi, I'm trying to execute a compute shader from a burst job, i'm not really sure what I'm doing but I'm wondering if this is even possible, all I found is some Reddit threads from 2019/2020 that claim that as of right now Unity does not support this. Any updates on this?

#

I'm not trying to asynchronously run compute shaders, just offloading the dispatch to a separate thread.

cosmic rain
cosmic rain
#

In the first place, I'm not sure dispatching a compute shader is thread safe API, so it might not work at all even if you were to run it from your own thread(not a job).

viscid plaza
#

I have a scene that is missing a script, but it doesn't let me assign it to it...

#

Completely locked out.

viscid plaza
#

I know exactly what script is missing, but it doesn't let me assign it

#

And no compiler errors, in case you wanna know.

leaden ice
viscid plaza
#

The scene

leaden ice
#

Why would the scene have a script reference on it? That's not a thing

viscid plaza
#

Well I guess it might be in the scene, but it's weird that it's not letting me open it at all.

leaden ice
#

what you have there is some kind of corrupted asset

#

the scene file is corrupted

#

A normal scene inspector just looks like this

#

what is the file extension of that file

viscid plaza
#

๐Ÿ—ฟ nevermind

#

I confused TitleScreen with MainMenu (I didn't name them)

#

Well now I gotta figure out where the heck this Main Menu prefab is being used and fix whatever that error is.

#

Anyway, thanks guys

leaden ice
viscid plaza
#

It has a prefab file extension

#

But oh well problem for another day

swift falcon
#

Hey does anyone how or where I could get URP settings for a Quest game? I hardly have anything in my scene and its topping 50 fps

cosmic rain
past knot
#

hello guys, im new to the unity new input system, i did a lot of research and didnt found a specific method for tracking wich key is being pressed. I created a vector2 tab for movement and i need to track when the player is pressing A, W, S or D

dusk apex
# past knot hello guys, im new to the unity new input system, i did a lot of research and di...

The first hit on Google yielded me this
https://youtu.be/0z-6lxL_sS4
What's the specific issue that you're having?

๐Ÿšจ Wishlist Revolocity on Steam! https://store.steampowered.com/app/2762050/Revolocity/ ๐Ÿšจ Creating a similar input to Input.GetKey in Unity's new Input System can be a real pain, but if you're looking for an equivalent on GetKey in the new input system then this Unity tutorial will hopefully help!

๐Ÿ“ Get access to my tutorial project files over o...

โ–ถ Play video
cosmic rain
swift falcon
warm cosmos
#

this error appears sometimes when I end a play session or even sometimes when I launch the project

#

it doesn't show me a callstack or anything, so I am not sure how to track this down

past knot
#

i set some bounderies that the player cannot cross

cosmic rain
#

Are you using any custom editors/inspectors that could be breaking?

warm cosmos
#

I do have some custom editor scripts

cosmic rain
warm cosmos
#

okay, I will try to figure out where it might be coming from, thanks

eager fulcrum
#

hey I have this setup
on the Cubes I have a box collider and simple script:

public Vector3 targetRotation;
public Camera raycastCam;

public void OnMouseDown()
{
    if (Input.GetMouseButtonDown(0))
    {
        RaycastHit hit;
        if (Physics.Raycast(raycastCam.ScreenPointToRay(Input.mousePosition), out hit))
        {
            if (hit.collider.gameObject == gameObject)
            {
                Camera.main.transform.rotation = Quaternion.Euler(targetRotation);
            }
        }
    }
}
#

any ideas why this is not detecting the mouse click?

#

Cubes have a layer Gizmo which Main Camera doesn't render. Only PerspectiveGizmoCam renders it

#

raycastCam is PerspectiveGizmoCam

mellow sigil
#

You're combining two separate things. OnMouseDown only triggers when clicking on the object that has this script. You don't need to check for mouse click and do a raycast separately.

eager fulcrum
#

ah my bad, I thought it only triggers when mouse was hoovering over it

#

but yeah, it still doenst work

mellow sigil
#

So either change the method to Update and put it on only one object, or just put

public void OnMouseDown()
{
    Camera.main.transform.rotation = Quaternion.Euler(targetRotation);
}

on all objects you want this to apply

eager fulcrum
#

okay moving it to Update works

#

but now there is some issue with rotating

#

it doesnt change the rotation of that object at all

mellow sigil
#

The only rotation that the script changes is the main camera's

fair osprey
#

ahoi, I have a piece of code on an object with a collider that executes in OnMouseDown(). Works flawlessly so far. Now my issue is that I want code executed in my movement update function when I press the mouse button but ONLY if the other object's OnMouseDown isn't triggered

#

so the object should always take priority but if it isnt hit with the mouse click some other code in a different script should execute globally

mellow sigil
#

OnMouseDown is only for simple cases, for things like this it's probably better to do a raycast manually and then do the other thing if it doesn't hit the object

fair osprey
#

so in my case, do a raycast instead of the onmousedown, if it hits the object call a function on it that does the code previously in my onmousedown, if not do whatever else I wanted yeah?

mellow sigil
#

Right, or if you want to get fancy, have it trigger events

fair osprey
#

I shall ponder my willingness to get fancy, thanks for the input

#

I have proven unable to get a hit with my raycast

#

nvm I was just being stupid

#

think it all works now, ty again for the help

warm bison
#

hey, has someone followed that video ? https://www.youtube.com/watch?v=rSKMYc1CQHE ? only few seconds after begining he's using method DrawCircle() and I can't get it..

Let's try to convince a bunch of particles to behave (at least somewhat) like water.
Written in C# and HLSL, and running inside the Unity engine.

Source code:
https://github.com/SebLague/Fluid-Sim

If you'd like to support me in creating more videos like this, you can do so here:
https://www.patreon.com/SebastianLague
https://ko-fi.com/sebastia...

โ–ถ Play video
mellow sigil
#

It's not really the kind of tutorial where you'd copy code directly from the video. Drawing the circle is an implementation detail that's not important to the main point he's trying to get across. You can use a sprite or 3d sphere for example if you want to follow along

#

But I'd suggest first just viewing the video through without doing anything yourself, and then going back to the start

warm bison
# mellow sigil But I'd suggest first just viewing the video through without doing anything your...

thanks for u answer, tho I yet cloned his project in the past and just some weeks ago I implemented a delaunay's triangulation on points from a Binary Spatial Partition to make a Dungeon Generator ( with Kruskal to get the MST ). I would had liked that DrawCircle method to visualize the circumcircles and but had to use gizmos. watching the video I thought that method existed natively on unity, will experiment that simu with a sprite as u say ^^

languid hound
#

I've seen that a decent few popular games make capsules "hover" on the ground. How is this actually done?

#

I would assume you're shooting a ray from the capsule but like.. what if the capsule intersects something and the ray fails?

#

It's not the springy sort of hover either its really snappy

swift falcon
#

Guys are any of these bounds considering object's rotation? (mesh bounds, renderer bounds, collider bounds)
And if not, how do i rotate them?

cosmic rain
languid hound
#

Maybe I'm just overthinking it tbh the scenario I gave was very uncommon. I'm just considering a floating capsule as an alternative to the sliding one right now since I'm having some horrible issues with keeping floor contact

cosmic rain
swift falcon
cosmic rain
round violet
#

i got a prefab that I instance, this prefab has a lot of gameobjects with rigidbodies
when i do a trace i hit one of those rigidbodies, i would like to get the "top parent" of this prefab instance

#

is this possible ?

thick terrace
round violet
#

yeah why not

#

thanks

knotty sun
round violet
#

thanks

upper pilot
#

Hey, how can I detect if coroutine was stopped?

I.e. I do StopCoroutine(myCoroutine)
How can I detect that it was stopped inside that corutine?

knotty sun
#

you cannot, Coroutines pause on a yield statement, if the coroutine is stopped it just does not return from that statement

upper pilot
#

Makes sense, thanks

marble sonnet
#

can someone make me a script for moving an object because i have been trying since yesterday

maiden fractal
#

No, not on this channel or any other on this server

slate turtle
#

Iโ€™m learning c# and already have experience with python and JavaScript. How much c# do I need to know to be efficient with unity

mellow sigil
#

42%

slate turtle
#

Like after learning classes is there much else for me to know

mellow sigil
#

Yes, a lot. It's a lifetime learning journey. But it's not a thing that you should be worrying about, just start doing and learn on the way

slate turtle
#

And in terms of a free ide, should I use rider or visual studio

knotty sun
thin aurora
#

I would probably choose Rider if I start using it

maiden fractal
#

VSCode though hasn't been supported for couple years so the community one might be of choise

knotty sun
#

Nah, Rider is like having a nagging mother looking over your shoulder

spark quarry
#

hello! I would likt to ask how to program some UI stuff I am trying to do, is this the right channel?

spark quarry
knotty sun
fast dune
#

are built-in components like Position Constraint or Audio Source monobehaviors? i.e., do they have Update() functions?

thick terrace
swift falcon
#

if i want monobehaviour on a tree then i need to place object trees or can this be done on terraintrees ?

rigid island
swift falcon
rigid island
young tapir
#

Could I somehow make a dropdown list of all the classes that inherit from a base class? I'm trying to create a small list of every collider type to select from

steady moat
#

However, I would just hardcode them given that we are talking about collider type.

leaden ice
#

probably simplest to just manually list them

#

MeshCollider, BoxCollider, SphereCollider, CapsuleCollider

young tapir
#

I was just going to use an enum for them haha. Thought it might be nice to have an adaptive selection but I guess there really isn't much point

leaden ice
#

yeah only 4 even ๐Ÿ™‚

young tapir
#

Switch case my beloved

leaden ice
#

It would take more effort to write code that enumerates them all than to just enumerate them

young tapir
#

Guess I could also make a Component variable and just add that PepeThink

#

But then I'd have to check if it's a certain collider and that's far too much effort for a helper script I'll end up using twice

dim forge
#

Hey, I'm trying to render sprites as hotbar item icons. The hotbar itself is made out of Canvas Images, which is a UI element. I added a Sprite Renderer component to an empty object under the hotbar slot object (the Canvas). Seems like everything else is rendering on top of the Sprite. Anyone know how i could fix this? The orange outline in the image is the Sprite

leaden ice
#

not SpriteRenderer

#

SpriteRenderer is not for UI

dim forge
#

oh that makes sense, thanks!

#

i just got it confused because the Item class saves the Sprite of the item (colleagues design) so I thought i would have to render it as a sprite

leaden ice
dim forge
#

yeah, just noticed

leaden ice
#

The SpriteRenderer component renders Sprites in the game world

merry swift
#

My question, trying to get answer here Ddd

modern creek
#

If you're going for ultra-realism, strap a gopro to your head, look at a fixed point, run towards it, then replay the video and graph the offset of the point (both x and y) in a pair of animation curves, and voila! nauseating head motion. ๐Ÿ™‚

#

(I think head bob is best done in a very, very subtle way - so subtle that it probably doesn't matter what kind of curve you use, you just want a little bit of wobble)

real gate
#

can someone help me make a pause menu ive tried 29482942 different scripts none work when i press escape nothing happens the menu canvas doesnt show up and even if it does the buttons dont work

fallow quartz
#

Is there any other solution to shared variables / methods apart from inheritance? I have some classes that share variables, other classes that share other variables, and all of them share other variables

#

I want to get rid of duplicate code but inheritance is not good for this situation

fallow quartz
#

for only 1 variable change

knotty sun
fallow quartz
#

and if u change it in 1 object