#archived-code-general

1 messages ยท Page 311 of 1

latent latch
#

Really the problem is the editor I guess to say

#

Yeah, the problem is I would like to hide some enum entries on the editor but I guess that's some editor scripting I can't be bothered with

lean sail
chilly surge
#

Now that Microsoft is developing C# Dev Kit and slapping on the same license as VS, as well as developing the Unity extension, it seems to me that they have full intention to keep developing and making money off of it, so I'm optimistic about it.
Been using VS Code for Unity and that transition period between Unity dropping support and Microsoft picking up the torch was pretty rough, but now things seem to sail in the right direction again.

latent latch
#

onvalidate would prevent flags from being selected but it would still show them all if I stuck to a single enum

#

just another case of unity's terrible editor support for compositional programming

twilit scaffold
chilly surge
#

AFAIK it should work there.

dawn nebula
#

What're you trying to do?

latent latch
dawn nebula
#

Oh I was talking more about what these Enums represent.

latent latch
#

so you can think of my class such that ActiveEffect derives from Effect, but only ActiveEffect has values of duration and interval

#

they just represent values you can further modify

#

so one option is just make another enum for each derived class, but then it's just a lot of extra type checking

sullen drift
#

anyone has a tutorial project that i could learn about bubble shooter game in 2d?

vague tundra
#

I have an animation that is played using the Animator component.
In the animation, the player swings a sword through the scene.
The sword has a collider.
How might I go about appropriately detecting collisions between the sword and other objects? I suspect the animation is occurring in the regular Update method, so I am wondering how to correctly perform collision-checks with respect to the Physics side of things

dense swan
#

hello, sometimes JSONUtility.FromJson() can error when the input string is invalid. And the execution will just stop (it doesn't go to the next line).
This function doesn't seem to output error or anything, it just return the result.
Can I tell this function to use default value if it failed because the input is invalid?

vague tundra
lean sail
dense swan
# lean sail show the code, also can you show the string and the Type?

I intentionally use invalid input string to test in case player mess with their save file and broke it.
When that happened, I wanted to use default value.

this is the code

SaveData data = new();
data = JsonUtility.FromJson<SaveData>("rstrsta");

this is the type

class SaveData {
        public bool opened;
        public bool locked;
    }
lean sail
#

can you show the entire code

dense swan
#

no no I see the error in the console. I mean the function doesn't tell me if the input is invalid.

lean sail
#

Ah, then yea just wrap it in a try catch and itll be fine

#

although I wouldnt exactly catch Exception as shown above, its better if you specify the error which is ArgumentException here. If your SaveData class gets more complex, I would just manually plug in data to ensure its what you want as a default file.

        SaveData saveData;
        try
        {
            saveData = JsonUtility.FromJson<saveData>(jsonString);
        }
        catch (ArgumentException e)
        {
            Debug.LogError(e);
            saveData = new(whatever);
        }

Maybe directly tell the user the file broke too so they dont do it again

lean sail
slim gate
#

I have this event; it is getting invoked, because "Invoking Event" appears in the console.

public class Player : NetworkBehaviour
{
    public event Action OnCharacterChange;
    private void CharacterChange(Id oldValue, Id newValue)
    {
        if (IsCharacterSetup())
        {
            Debug.Log("Invoking Event");
            OnCharacterChange?.Invoke();
        }
    }
}

Then in another class I have this where I subscribe to the event:

private Player _player;
public void Setup(Player player)
{
    _player = player;

    _player.OnCharacterChange += UpdateBanner;
}

private void OnDisable()
{
    _player.OnCharacterChange -= UpdateBanner;
}

Now the problem is, that UpdateBanner is not getting called when I invoke the event, and I dont know why. Any Ideas?

cosmic rain
#

Stepping with a debugger would unveil the mystery

slim gate
#

hmmm okay, I really should learn that

#

Ive been debugging with Debug.Log for years

torpid aspen
#

can anybody help me please? I'm coding and I'm stuck for a while on one thing

hazy pike
#

Im having a small problem with my inventory system. It works and everything and I have a script for dragging and dropping items between slots but it only drags and drops them in the UI, meaning that the index of the item in the array does not change according to its position after I moved it. I also have a script attached to each slot prefab which handles the ondrop event. Can someone please suggest how I can fix this issue?

#

to clarify more, the issue here is I can only move the icons of the item in my inventory and not the item itself

#

I'd be thankful if someone gave a solution as ive been stuck on that for like 5 days now.

night harness
#

Ok so ya'll are probably gonna hit me with a "do it another way" buuuuut

If I did want to instantiate a ton of gameobjects at bulk (hundreds-couple thousand max), Is there an ideal way to do that performance wise?

#

Does unity have something built for that i should be using instead of just spawning them each

leaden ice
night harness
leaden ice
#

What are the objects?

#

Instantiate them ahead of time or do something else like a particle system

static matrix
#

does making a variable public have any effect on runtime perf?
just to clarify, if the answer is "yes but one its not much" that is still important because I have the very very very bad habit of publicing almost allll my variables

mental rover
fervent furnace
#

access modifer doesnt exists in asm

late lion
static matrix
#

idk seems to make things easier for me but im weird
okay good to know

loud wharf
#

If it gets too complex, you can use record structs instead.
And a good ol custom editor.

late lion
loud wharf
#

You'd get more freedom with it.

static matrix
tidal nebula
#

Hi there Can some One help me with integrating Ads if they have done it before please provide the script and the method to do so i have tried unity doc's and youtube but wasn't able to do it succesfully

#

also i need Help with NavMesh it is not there in the designated place like with the physics and all that stuff

static matrix
#

punctuation is a neat little thing
idk if unity has a built in ad feature or not
Navmesh is under navigation, not physics

fervent furnace
#

unity ad, but i havent used it

static matrix
#

I presume this would be for a mobile game
you are absolutely deranged if you think putting ads in a downloadable game is a good idea (no offense)

woven mirage
#

@swift falcon whomp whomp :)

placid summit
#

Hi with TMP_InputField if you do not press enter and click another control it resets by default it seems, which is not too useful! Is that an inspector setting?

somber nacelle
#

are you certain you aren't just clearing the input field in OnEndEdit or something?

placid summit
#

yes - I change text - click another control - the text resets to previous state

#

but let me check something...

#

ah ok maybe I am interupting TMP with this UI

#

the help docs are basically missing for TMP?

rigid island
placid summit
placid summit
#

but does not cover UGUI?

rigid island
#

its the whole package, UI & mesh

placid summit
#

hmm nothing for TMP_Inputfield except in scripting that I can see. Maybe you are supposed to reference UGUI adn TMP docs together

placid summit
#

no help reference for inspector side

#

the help button in 2022 is a broken link for that component

rigid island
#

inspector side?

placid summit
#

in the editor - I can click ? on any normal UGUI component in inspector and get help

rigid island
placid summit
#

oh so TMP_InputField has an onSubmit listener and an onDeselect listener - should be an inspector setting to make deselect call onSubmit but... maybe not? I think NGUI had one

tepid brook
#

Hi guys, my script is working well in the Editor but when i build the game i have an error like "object reference not set to an instance of an object"

knotty sun
leaden ice
tepid brook
naive summit
#

Guys, quick question. Barrely started on new code for my game and already getting an error
So this is the code

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class WhoAmI : MonoBehaviour
{

    public GameObject whoami;

    // Start is called before the first frame update
    void Start()
    {
        whoami.SetActive = true;
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

and the error im getting is, - Cannot assign to 'SetActive' because it is a 'method group' -
Why?

#

Quick mention that whoami GameObject is an UI inside Canvas

tepid brook
#

maybe because SetActive is a function not a bool so you have to do whoami.SetActive(true);

knotty sun
naive summit
knotty sun
tawny elkBOT
tepid brook
knotty sun
waxen blade
#

I am trying to create a scriptable object that can be created and have its values be modified in the Unity editor. I can make it work for existing data types like int, bool, string, etc. But is there a way I can make it work with my own unique class? In the screenshot the TestObject class is not showing up and I can't modify its values in the editor. Only the bool is showing.

[CreateAssetMenu]
public class TestScriptableObject : ScriptableObject
{
    public TestObject testObject;
    public bool isTest;

    public TestScriptableObject(TestObject testObject, bool isTest)
    {
        this.testObject = testObject;
        this.isTest = isTest;
    }
}
public class TestObject
{
    public int testInt { get; set; }
    public string testString { get; set; }
}
somber nacelle
#

the class needs to be Serializable. and unity also doesn't serialize properties, you'd have to either use explicit backing fields or target the backing fields of those auto properties for the SerializeField attribute like [field:SerializeField]

waxen blade
leaden ice
#

Unity's serializer can only serialize fields not Properties

#

properties are functions.

#

when you do:

public int Score { get; set; }``` the C# compiler automatically creates an invisible backing field for you
leaden ice
#

since it should be created generally with ScriptableObject.CreateInstance<T>

waxen blade
leaden ice
#

Pick one. Either will work.

#

add [field:SeralizeField] or convert to a manual backing field like my example and serialize that backing field

#

You just need to serialize the field somehow

#

Also don't forget to make the class itself [Serializable]

#

I showed my example mainly by way of illustration to help you understand the relationship between properties and fields

waxen blade
#

I got it, I have it working now. I originally didn't realize they were two different ways of achieving the same goal.

waxen blade
leaden ice
#

Instantiate just clones an existing one, CreateInstance creates a fresh one

waxen blade
leaden ice
#

Some tutorials are not well written

tepid brook
#

Because my problem is i enable my second canvas but he stay disable

#

in the build

leaden ice
#

There is no issue with using as many canvases as you want.

tepid brook
#

i don't know what is the problem then x)

leaden ice
#

Have you checked the logs for errors

tepid brook
#

yes i have no error

#

the last debug return false xD

#

i enable 2 time the canvas

leaden ice
#

That doesn't tell us if you have an error

tepid brook
#

i don't

leaden ice
#

you'll want to look at the player logs

#

also you're using a deprecated property there

#

(as the warning is telling you)

tepid brook
leaden ice
#

sure but it's not the right property

turbid river
#

hey guys, i have a really really dumb question, but sometimes i feel like i put too many if statements in my code and it just makes me wonder if "good" code or rather, actual game codes include a lot of if statements..any opinion is appreciated, thanks

leaden ice
#

do you know the difference between activeSelf and activeInHierarchy? It's possible to SetActive and still be not active in hierarchy

leaden ice
turbid river
#

@leaden ice okay so for example im messing around with a silly idea of a plane game and i have a shit ton of conditionals regarding the current angle of the plane what i want to be done at what angle etc

turbid river
leaden ice
#

yes this code is bad

turbid river
#

LMAO

#

thanks

leaden ice
#

anyway !code for sharing code

tawny elkBOT
turbid river
#

why is it bad

gray mural
leaden ice
#
  1. reliance on euler angles
  2. way too many repeated calls to the same property which is very inefficient transform.eulerAngles
  3. too much nesting
#

also yes sharing as an image is ๐Ÿคฎ

turbid river
#

apologies my friends

#

please be patient with my fragile ego

turbid river
#

dont tell me i have to work with quaternions

leaden ice
#

euler angles are subject to gimbal lock. They're also cyclical so it's not trivial to do comparisons

#

Quaternions are much easier to work with

#

but also rethinking your problem not in terms of euler angles often leads to simpler and more reliable code.

#

Like this for example is not reliable. Unity may give you an angle of -40. Which is equivalent to 320 degrees but this code won't catch it

#

it's much better not to deal with euler angles like this at all

turbid river
#

thats true but i noticed that whenever it goes below zero and it instantly becomes 360

#

are you saying it can sometimes become negative?

leaden ice
#

yes. And euler angles cannot be taken and compared in isolation due to gimbal lock

#

(180, 180, 0) is the same as (0, 0, 180) for example

#

but the first won't be noticed if you are only looking at Z. Euler angles cannot be analyzed in isolation safely.

#

They're just a nightmare to deal with.

turbid river
#

i understand

leaden ice
#

It's better to do something like:

float angle = Vector3.Angle(transform.up, Quaternion.Euler(0, 0, 305) * Vector3.up)); // compare your up to 305 degrees tilted up (which is the middle of 270 and 340)
if (angle < 22.5f) {
  // this is the same check as your code but without the transform euler angle pitfalls
}```
turbid river
#

so you take the global up vector and you rotate it 305 degrees?

low pike
#

How I can make that player must click buttons (objects) in specific order?

leaden ice
#

record as they click each thing and compare that to the expected order

turbid river
#

doesnt that become 395 degrees technically?

#

am i missing something

leaden ice
turbid river
#

oh nvm hold on

leaden ice
#

so it's 305 from there

#

since we normally expect the object up to be pointing... up

turbid river
#

it doesnt have to be up though right? i can use "right" as well

#

shouldnt the angle be 35? not 22.5?

#

but yeah this seems like a better way of doing things

#

thank you sir

leaden ice
#

Other things would be - invert your early-out conditions for less nesting

#

instead of:

if (!grounded) {
  // all your code
}```It's often better to do something like:
```cs
if (grounded) return;

// all your code```
#

then you have less nesting

turbid river
#

noted

heady iris
#

you can also punt it into another method

#

although, if the code requires lots of local variables from earlier in the function, that can be difficult

turbid river
#

@leaden ice and how should i rotate things properly? multiply my transform by a quaternion vector?

leaden ice
#

you can't multiply a Transform by things, and quaternion vector is not a thing

#

"how should I rotate things properly" is a pretty vague question so I don't really know how to answer it

#

lots of things can be rotated in lots of different ways to achieve lots of different effects.

turbid river
#

i meant something like transform.right * quaternion.euler(0,0,angle)

leaden ice
#

that's not valid code

#

since the quaternion needs to be on the left of the *

turbid river
#

oh

#

okay and after swapping?

leaden ice
#

it also depends what you're trying to do here

turbid river
#

i just want to rotate the z axis by some angle

leaden ice
#

you want to rotate the object?

turbid river
#

yes

leaden ice
#

then you use either:

transform.rotation *= <some quaternion>```
or ```cs
transform.Rotate(<some euler angle vector>)```
turbid river
#

ok thank you ๐Ÿ™

woven veldt
#

Hi everyone. I really want to try and get a conveyor building system like those seen in games like satisfactory. Iโ€™ve done some research on Beizer curves and splines however I canโ€™t get a constant velocity. Is there a package out there that already handles this?

magic harness
#

have you tried setting velocity manually?

#

Btw, hey guys. I'm making an RPG and my mouse click is going to have a lot of different responsibilities.

  1. Move
  2. Target an Enemy
  3. Attack an Enemy if one is targetted
  4. Cast a skill if there is one selected
  5. Pick up loot
  6. Interact with an NPC

Any ways to make this not be a spaghetti code? Right now i'm raycasting and doing a bunch of different checks and that doesnt seem right, but i also dont really want to have a script on every object i need to interact with checking for onMouseDown and then changing static variables as that also is very much the spaghetti i wanted to avoid centralizing my inputs.

Using the new input system btw

leaden ice
#

Use a state machine

magic harness
#

shit i didnt think about that

#

but how should it gather information? Raycasting or on mouse hover/ on mouse down events?

leaden ice
#

how should what gather information?
Each state has different things it cares about right? Something like mousing over objects can be routed through some kind of dispatcher that dispatches that information to the current state.

#

definitely use the event system

#

i.e. IPointerEnterHandler et al

magic harness
#

Uhm... That might be the right track for sure. I'll think about it a bit for sure

sage narwhal
#

Is there an optimal way of checking whether a GameObject is falling?

This is what I have so far but I'm not sure how to improve it:

private void FixedUpdate(){
    previousHeight = transform.position.y * Time.deltaTime * 100;
}

private void LateUpdate(){
    currentHeight = transform.position.y * Time.deltaTime * 100;
    if (currentHeight < previousHeight - 0.11f)
    {
         //PLAYER IS FALLING
    }
}

There's probably a fault in this but both print the same thing when a GameObject is falling

lean sail
gleaming spruce
lean sail
gleaming spruce
gleaming spruce
sage narwhal
sage narwhal
lean sail
#

All of this really can just be in update, if you have a rigidbody with interpolate or arent using rb.

sage narwhal
#

I'm using a rb without interpolate

leaden ice
#

Just check if velocity.y is negative

sage narwhal
#

Since these values pop up whilst the player is on the ground, should I just check if it's lower than -0.1 or 0.2?

leaden ice
#

You'll want to be not grounded and have negative velocity

simple egret
#

These values are very close to 0, but not exactly 0. But yes they should be ignored when grounded

sage narwhal
#

Got it, I've applied the change and now it works perfectly - thanks ๐Ÿ™‚

paper pond
#

I have a pipe object with a BoxCollider2D and I have a drill that gets shot through the pipe that also uses a BoxCollider2D but as trigger. I've used a sprite mask to create a hole through the pipe but I need to somehow create a hole through the collider. I was thinking adding a second collider to the pipe and setting the bounds of the colliders to those of the drill but I can't seem to get it to work. Anybody know any other solutions?

urban light
#

Hello! Just a quick question how do I make sure my navmesh is apply correctly, as is right now my agent is failing to create.

rigid island
#

is agent close enough

rigid island
urban light
rigid island
paper pond
#

or do they have to be relative to the center

rigid island
paper pond
#

okay ty

rigid island
#

np

urban light
slate imp
#

Hi there, i'm trying to create a voxel engine, for now i have a thing that can pop cube entities when i press space. My question is, should i put my hands in the mud to change of instead creating cubes, it instead manage all the verticies and merges them when two voxels side a side have the same color and aswell as not loading those who are not seen by the camera ? or is their some already existing things that can help me ?

latent latch
#

can you write out that question again

slate imp
#

i asked gpt to rephrase it, not sure if it will be more usterstandable :

Hello, I'm working on developing a voxel engine. Currently, I have a feature that generates cube entities when I press the space bar. I'm wondering if I should manually modify the code to manage all the vertices and merge them when two adjacent voxels have the same color, as well as not loading those that are not visible to the camera? Or are there existing tools or libraries that could assist me in achieving this?
leaden ice
#

there are plenty of Unity Minecraft type tutorials floating around you can base your work off.

slate imp
# latent latch can you write out that question again

Well in other words, actually what i have :

  • I press space : one cube spawn next to the previous in a grid

My goal :

  • Having a voxel engine
  • Having it optimized

My thoughs :

  1. Instead of creating a whole cube each time i spawn a voxel, manage verticies
  2. Instead of spawning all verticies, spawning only who are visible
  3. Merging verticies that have the same color to have less entities

Another though :

  • is their some things that handle my goal without rewriting everything from scratch ?
slate imp
latent latch
#

individual gameobjects can work if you eventually merge the meshes together at the end, but the biggest problem I've ran into on the editor is that you'll run into performance problems very quickly cause you're editing these objects without batching

#

rather, very limited batching as stuff like static batching is runtime specific

slate imp
#

I though about something that could handle verticies merge and things like this automatically, i just give him the camera position and all the verticies or all the voxel position and it will automatically display only the verticies and merging them to prevent having too much entities

#

Batching will be for handling spawning some chunk of voxels at a time, like one batch for 4 chunks of voxels

latent latch
#

I'd just look into the typical voxel generation and chunkiing before deciding on anything custom if you're not familiar with it

#

unity already does a lot of optimizations you may not be aware of so you don't need to think too hard about culling and batching beyond just not having a billion gameobjects on the scene

slate imp
slate imp
latent latch
#

well the idea with chunks is more chunks = less draw calls

#

but if you're editing a chunk at runtime every so often, then you are rebuilding that chunk everytime so bigger chunk more rebuilding and redrawing

slate imp
latent latch
#

bigger chunks also create problems for frustrum culling as when you render a bit of that chunk it will render all of it (backface culling from your shader will help lessen what's visible though), so there's some balancing to be done

slate imp
#

once again, my question wasn't about this, it was about verticies merging and things like this. Because actually i have a bunch of verticies for each cube and a lot that not even displayed because they are not facing the camera. I'd like to know if their are some built in tools to handle this kind of things

#

Actually i can spawn about 12k cubes, but at 12k cubes my frame rates drops to 40fps only because of the rendering, without any computing on top, just having the game running

latent latch
#

if it's not in view of the camera it will be culled by default via frustrum culling

#

if it's a large plane that's a single mesh and it expands behind you, then that back part wont be culled if you're looking at the front of it

slate imp
latent latch
#

in that case you probably have a lot of room to work with. I'd chunk your meshes about a screensize worth and playing around with that

slate imp
slate imp
#

So what i'm asking was about the display engine, i have a bunch of voxel to display, how to make it work, how to know when voxels meshes are connecting, without going x^2 times into the array of voxels, is their some techs or math that could make things easier

latent latch
#

between backface culling and frustum culling you only need to worry about how much is visible relative to the camera, and chunked enough that it only needs to compare against a limited amount of meshes. If you do want some more optimizations, make sure you're removing faces of your voxels that are centered to your meshes such that no faces should be exposed.

latent latch
#

array of chunks which contain an array of voxels

slate imp
slate imp
latent latch
slate imp
#

thanks

latent latch
#

"Also, what do you mean by make sure you're removing faces of your voxels that are centered to your meshes such that no faces should be exposed"
It's the concept of "Air" blocks which 'exist' in data but shouldnt be rendered because there are voxels surrounding it

slate imp
latent latch
#

basically if you're rebuilding your chunks you just want to build the verts that can be visible to the user

shell scarab
#

Hey guys, I'm getting this error from unity when I'm removing things from a list:

InvalidOperationException: The operation is not possible when moved past all properties (Next returned false)
UnityEditor.SerializedProperty.Verify (UnityEditor.SerializedProperty+VerifyFlags verifyFlags) (at <5e6ebaa7d75c4d5399dc81ecead6b43f>:0)
UnityEditor.SerializedProperty.get_objectReferenceInstanceIDValue () (at <5e6ebaa7d75c4d5399dc81ecead6b43f>:0)
UnityEditor.EditorGUIUtility.ObjectContent (UnityEngine.Object obj, System.Type type, UnityEditor.SerializedProperty property, UnityEditor.EditorGUI+ObjectFieldValidator validator) (at <5e6ebaa7d75c4d5399dc81ecead6b43f>:0)
UnityEditor.UIElements.ObjectField+ObjectFieldDisplay.Update () (at <5e6ebaa7d75c4d5399dc81ecead6b43f>:0)
UnityEditor.UIElements.ObjectField.UpdateDisplay () (at <5e6ebaa7d75c4d5399dc81ecead6b43f>:0)
UnityEngine.UIElements.VisualElement+SimpleScheduledItem.PerformTimerUpdate (UnityEngine.UIElements.TimerState state) (at <383db090fd544f24b368fd389016a28f>:0)
UnityEngine.UIElements.TimerEventScheduler.UpdateScheduledEvents () (at <383db090fd544f24b368fd389016a28f>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at <383db090fd544f24b368fd389016a28f>:0)
UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at <383db090fd544f24b368fd389016a28f>:0)
UnityEditor.RetainedMode.UpdateSchedulers () (at <3104ccaa0bea414cad8743a20c82e823>:0)

I'm assuming that I should just ignore it? I'm pretty sure there's nothing I can do to stop that. It only occurs when the object is being inspected and something is removed from the list. If the last element of the list is removed, it spams this error.

#

I also get this error when inspecting the object and something is removed that's not the last element in the list:

ObjectDisposedException: SerializedProperty _allPlayerUnits.Array.data[0] has disappeared!
UnityEditor.SerializedProperty.Verify (UnityEditor.SerializedProperty+VerifyFlags verifyFlags) (at <5e6ebaa7d75c4d5399dc81ecead6b43f>:0)
UnityEditor.SerializedProperty.get_objectReferenceInstanceIDValue () (at <5e6ebaa7d75c4d5399dc81ecead6b43f>:0)
UnityEditor.EditorGUIUtility.ObjectContent (UnityEngine.Object obj, System.Type type, UnityEditor.SerializedProperty property, UnityEditor.EditorGUI+ObjectFieldValidator validator) (at <5e6ebaa7d75c4d5399dc81ecead6b43f>:0)
UnityEditor.UIElements.ObjectField+ObjectFieldDisplay.Update () (at <5e6ebaa7d75c4d5399dc81ecead6b43f>:0)
UnityEditor.UIElements.ObjectField.UpdateDisplay () (at <5e6ebaa7d75c4d5399dc81ecead6b43f>:0)
UnityEngine.UIElements.VisualElement+SimpleScheduledItem.PerformTimerUpdate (UnityEngine.UIElements.TimerState state) (at <383db090fd544f24b368fd389016a28f>:0)
UnityEngine.UIElements.TimerEventScheduler.UpdateScheduledEvents () (at <383db090fd544f24b368fd389016a28f>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at <383db090fd544f24b368fd389016a28f>:0)
UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at <383db090fd544f24b368fd389016a28f>:0)
UnityEditor.RetainedMode.UpdateSchedulers () (at <3104ccaa0bea414cad8743a20c82e823>:0)
#

Again I'm pretty sure I should just ignore these, I don't think I'm doing anything wrong. It only happens when I remove from the list.

heady iris
#

Have you restarted unity?

shell scarab
#

yea :(

heady iris
#

It's alarming to see problems from the actual serialized property code

shell scarab
#

Oh, it also just occured to me that the inspector is displaying two lists that sometimes share objects, so maybe it's related to that. (for debugging reasons)

heady iris
#

I've definitely seen errors like this in...pretty tame situations

#

I have yet to have that coincide with actual permanent problems

#

i.e. corrupted or missing serialized data

shell scarab
#

Ok, but it shouldn't be something I'm doing right? Especially if I don't have a custom editor?

shell scarab
vapid lynx
#

im kinda confused why im getting the error

rigid island
vapid lynx
rigid island
vapid lynx
#

yeah

#

it shows no error in unity

rigid island
#

try regen project files maybe

vapid lynx
#

alr

vapid lynx
#

what does this error mean

#

nvm i tihnk i figuted it out

grave thorn
#

Hey eveyone, Im trying to make an enemy indicator in a FPS 2D game... The indicator should turn on when the enemy is out of the screen and be on the edge of the screen and indicate where the enemy is. I dont know how to, any guidance?

latent latch
#

googles

lean sail
grave thorn
#

hmm so heres the current code.. it doesnt work.. https://youtu.be/pYEAwiKFKeg followed dis.. The indicator never turns on...

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyIndicator : MonoBehaviour
{
    GameObject indicator;
    GameObject player;
    Renderer rd;
    // Start is called before the first frame update
    void Start()
    {
        indicator = transform.GetChild(1).gameObject;
        rd = GetComponent<Renderer>();
        player = GameObject.Find("Player");
    }

    // Update is called once per frame
    void Update()
    {
        if (!rd.isVisible)
        {
            if (!indicator.activeSelf)
            {
                indicator.SetActive(true);
            }
        }

        Vector2 direction = player.transform.position - transform.position;
        RaycastHit2D hit = Physics2D.Raycast(transform.position, direction);

        if (hit.collider != null)
        {
            indicator.transform.position = hit.point;
        }
        else
        {
            if (indicator.activeSelf)
            {
                indicator.SetActive(false);
            }
        }
    }
}

Support me On Patreon : https://www.patreon.com/the_game_guy
It'll mean alot to me ๐Ÿ’–

In this video i will show you how to make a simple indicator that will point towards the enemies (or any other gameobject) outside the camera view so we can know where the enemies are coming from.

and there are a lots of ways to go about doing the same thing h...

โ–ถ Play video
golden wave
lean sail
grave thorn
#

ok ill do that nd let uk

merry stream
#

are the IPointer interfaces used with the old input system only?

#

if so, how would I translate them into the new input system

chilly surge
#

They should still work with the new input system.

thin aurora
heavy flume
modern hamlet
#

Hi folks. Anyone got an idea why the editor spams me with the Error Input Axis Horizontal not set up, when all I got is prefabPlayer1[i].GetComponent<PlayerScript>().ControlSchemeX = "Horizontal_P1"; and the axis is declared as Horizontal_P1 inside the input manager? (btw ControlSchemeX is just a getter/setter for a readonly String)

Also pretty weird because my input seems to work just fine and without any hiccups as far as I can tell. Nevertheless I'm worried about the spam I get with the above mentioned error.

Already thought of some kind of Awake vs Start issue, but that doesn't seem to be the case. (Version: 2022.3.25f1)

thin aurora
modern hamlet
#

Yeah, I read about that. Speeling is fine though - even copied the value right over.

thin aurora
#

Perhaps you have a duplicate saved somewhere which it complains about? Considering it does work for you

#

I'm not too familiar with the input system but it seems to complain about "Horizontal" rather than "Horizontal_P1"

modern hamlet
modern hamlet
thin aurora
#

No problem! Just so you likely get a better answer

dense swan
#

Hello, where do you usually put your camera rotation code in FPS game?

I have 75hz monitor, move character using CharacterController in FixedUpdate, animation in Normal mode. My camera look code is in Update, and I update my camera position in LateUpdate, my cinemachine brain is also LateUpdate (because it's gonna be jittery in Smart mode)

When I move my camera I can sense the jittery/choppy movement. It is fixed by moving my camera rotation in Fixed Update, but I'm afraid if I moved it to FixedUpdate, people with high refresh rate display will only see 60fps movement. But I don't know I can't test, I don't have high refresh rate display. I'm confused, I don't know what to do.

vestal arch
#

(FixedUpdate is 50 Hz by default btw)

knotty sun
#

If you are using CharacterController there is no need to use FixedUpdate at all, FixedUpdate is generally for physics related stuff which Character Controller does not have

placid summit
#

anyone understand xcode and signing?! My project used to work and now I get "Command CodeSign failed with a nonzero exit code"

lean sail
dense swan
dense swan
# lean sail Along with what Steve said, you shouldnt need to even worry about this because c...

hmm, I don't know if I have special case but using smart mode, Cinemachine liked to switch between two modes randomly (checked using the virtual camera), I don't remember what mode it is exactly but it made the camera jittery when Cinemachine moved to one certain mode. but maybe I was doing it wrong because some object will still looked jittery after I set it to LateUpdate but it's better since it's not very noticeable.

lean sail
signal ridge
#

How would people normally organize their Enums ? Coming from Web i would have had its own file for schemas basically. But how would i go about it in C# because leaving it inside the class seems bloated.

thick terrace
signal ridge
knotty sun
vague tundra
cosmic rain
#

I think it makes sense to define the enums in a class that they're most relatable to, like tool types in a tool class.

#

Or even outside of the class but in the same file

lilac lance
#

when I change the size between the scene and the project window, red lines appear, the buttons break up and it affects when I start the game and the buttons there also change, but I don't change their size, I just want to make the scene window smaller

gaunt holly
#

Hi, could someone help me to correctly do the movement and jumping system please?
The problems I currently have are:

  • when I move the player is blocked by a certain Tile
  • I can't jump (and even less while moving at the same time)

that's it, thank you, please mention me

thin aurora
tawny elkBOT
gaunt holly
signal ridge
vague tundra
lilac lance
gaunt holly
vague tundra
#

What's wrong with the jump?

gaunt holly
#

and also at twice the speed but not slow I get stuck in the corner of a tile

gaunt holly
slim gate
#

Makes it so the collider is one big one for the whole tilemap instead of one for each tile

vague tundra
#

Alright well these all sound like classic development issues.
I'd recommend trying to figure the problem out yourself as best you can, and if all else fails, ask a single, specific, well-explained question here and we can help(:

gaunt holly
slim gate
#

I think

slim gate
#

not sure cause its been a while since I did this

gaunt holly
#

Okay, so with a Composite Collider, all tile (the ground) fall and always the same problem

vestal arch
#

you missed the other step

slim gate
#

It tells you right next to the big exclamation mark

gaunt holly
#

I add it but the ground fall

vestal arch
#

you clearly did not add it, or you did not add it correctly

#

where's your composite collider?

gaunt holly
#

Yes, but I removed it since the floor was falling

vestal arch
#

ah, that's what you meant by fall

#

set the rigidbody type to Static

#

you need the compositecollider.

gaunt holly
vestal arch
#

set this to static

gaunt holly
#

mmm okay it's good

#

I will check to correctly set the jump now

#

thank you

clever leaf
#

hey, is there any way to snap from one animation clip to the other instantly? I have an animator that has a bool to make a character sit and when I transition between the states it sometimes makes it play a part of previous animation, I would like for it to snap to the sitting animation instantly

leaden ice
clever leaf
#

sorry, I was thinking about a code solution and my brain went here, my bad

runic linden
#

Can somebody with better knowledge of C# tell me if there are performance differences regarding those two functions?

public (string s, int i) GetTuple() { }

public void GetTuple(ref string s, ref int i) { }

(I use it for my dialogue handler who wants the next line as well as the speakers ID)

vestal arch
#

probably, but it'd be negligible

knotty sun
vestal arch
#

premature (micro)optimization territory

runic linden
#

Alright, thanks. ๐Ÿ™‚

slim gate
#

on that note

#

With singletons is there a significant difference wether i call Singleton.Instance.x every time or cache Singleton.Instance once and then use that?

knotty sun
#

no difference, an address is an address

vestal arch
knotty sun
vestal arch
#

in context, there'd be writing anyways for that function

#

so i guess there's just no difference for that, really?

knotty sun
#

I cannot tell, on the basis of a method signature, what that method does with it's data

vestal arch
#

it's comparing ref params to a return type though

#

assuming they do the same thing, those params would be assigned to?

knotty sun
#

then only the string would incurr overhead, the int would not

vestal arch
#

why wouldn't it

#

wouldn't it still need to copy over those 32 bits

knotty sun
#

no, strings cannot be updated, all pimitive values types can be

vestal arch
#

pretty sure primitives are immutable?

knotty sun
#

nope

vestal arch
#

and i don't see how that makes sense that that means it doesn't incur overhead

#

you still need to, yknow, do the assignment?

#

and it's a value type, so it's getting copied over regardless

#

aren't value types by definition immutable

vague tundra
#

Strings are a bit of a special case in most languages, but I believe strings are indeed reference types in C#

narrow nebula
#

when setting the text of a TMP_Text with a public string, how to include line breaks to the string in the editor, since \n doesn't work when set in the editor?

vestal arch
#

on c# docs;

The following table lists the C# built-in value types:
and then it lists all the primitives

knotty sun
#

no.
the original int declaration defines an address in stack space,
the ref parameter passes that address
inside the method the contents of the address are being updated.
no extra stack space allocation

vestal arch
#

yeah that applies to the string too?

#

and that's not what im referring to

#

im referring to the actual assignment

knotty sun
#

no, string are different, that is why strings should be avoided if possible

thick terrace
#

a ref is a pointer though, the ref int parameter is actually larger than an int technically

#

strings are just pointers too

knotty sun
#

no they are not

vestal arch
thick terrace
vestal arch
knotty sun
vague tundra
vestal arch
#

yeah, im not talking about that distinction at all

knotty sun
vestal arch
#

ok, what are they then

narrow nebula
vague tundra
knotty sun
vestal arch
#
string s = "asdf"; // 5 bytes on stack?
int i = 0;
s = "123456"; // did i overwrite `i`?
```they're on the heap, no? just like any other reference value?
thick terrace
vestal arch
knotty sun
#

yes, so not 'just a pointer'

vague tundra
vestal arch
#

im more lost about what you're talking about now

thick terrace
#

it's a pointer to a class which has 2 members

narrow nebula
#

in tmp text i can use enter

vague tundra
vestal arch
knotty sun
vague tundra
# narrow nebula in tmp text i can use enter

Give this attribute a try

public class MyComponent : MonoBehaviour {
    [TextArea(3, 10)]  // Specifies min and max number of visible lines
    public string multilineText;  // A multiline string field
}
chilly surge
#

String is a reference type.

vestal arch
#

if it stored its length on the stack, what about other reference types that store other lengths of things on the stack
you sure you don't just mean the size of the structure?

#

it's just a pointer with metadata. is it illegal to just be lazy and say "pointer"?

thick terrace
chilly surge
#

String has implemented value semantics, but strings are very much still heap objects. There is also string interning but that's an implementation detail.

vestal arch
#

.

besides all that, that's again not what im talking about with the overhead at all. im talking about literally just copying the int from one stack memory cell to another stack memory cell
it's still "overhead" to assign, despite how little overhead it may be
given that we're talking about the distinction between reading and writing ref values, and we're talking in technicalities, is assignment not overhead?

vestal arch
vague tundra
narrow nebula
thick terrace
chilly surge
#

The tuple return version has to make two copies when returning, but the ref parameter version has to pass pointers to the method, and all access to those parameters inside the method has to dereference the pointers, so it's not clear cut which one is faster either.

vestal arch
thick terrace
latent latch
#

ref looks cleaner so ref wins

thick terrace
#

yeah, if you're going to put 2+ values in a result tuple, you should define a struct for them imo ๐Ÿ˜›

chilly surge
vestal arch
vague tundra
latent latch
#

I dislike how minimal tuple syntax is, also accessing by key values if you don't define the parameters blehhhh

vestal arch
placid summit
#

tuples are evil, what was wrogn with structs ๐Ÿ™‚ But I like (a,b)=(b,a)

chilly surge
thick terrace
latent latch
chilly surge
#

Nope, you literally just use i and s.

#
var (i, s) = GetTuple();

Can be roughly think of as:

var _temp = GetTuple();
var i = _temp.Item1;
var s = _temp.Item2;
latent latch
#

ah, ok then that's probably fine then

placid summit
#

but a tuple is like an untyped struct right? going back to untyped objects seems a back step though for quick use OK

chilly surge
thick terrace
#

the original example named i and s too, so you could do GetTuple().s directly

#

if you ever need to write Item1, reconsider your choices lol

placid summit
chilly surge
#

You can also name it.

heady iris
#

C# is statically typed, unless you're using the evil dynamic keyword

heady iris
#

..but i guess i should be using KeyValuePair in that case

thick terrace
heady iris
#

๐Ÿ’ฅ

thick terrace
#

then you gotta name them or i'm calling the cops

chilly surge
#

A method signature of:

(int Foo, string Bar) GetTuple()

Will allow you to access the tuple members with their names:

var result = GetTuple()
Debug.Log(result.Foo);
Debug.Log(result.Bar);

But realistically you will just deconstruct them:

var (foo, bar) = GetTuple();
heady iris
#

nice!

chilly surge
#

And as a side note, instead of writing:

Debug.Log("someVariable=" + someVariable);
Debug.Log("someOtherVariable=" + someOtherVariable);

You can just use tuple:

Debug.Log((someVariable, someOtherVariable));

And it will log both variables with their names, making debugging stuffs way easier.

thick terrace
#

yeah, you can even name them in local declarations like var x = new List<(int i, string s)>()

chilly surge
#

Tuple allows for a lot of neat stuffs, it's not a must use feature but it makes a lot of things easier and worth learning about.

heady iris
#

trying to do it like in python

#

print(foo, bar, baz)

#

very neat; will keep that in mind

runic linden
#

Why does this

Debug.Log("Not successfull comparing " + speaker + " to " + _speakers[0].GetName() + ", " + speaker.Length + ", " + _speakers[0].GetName().Length);

debug this:

Not successful comparing Speakers: Froggo to Froggo, 16, 6

I am trying to compare the speakers name from my ink story (speaker) to my characters name in the scene (_speakers[0].GetName()) . The strings look the same in the console, but Unity tells me they have different lengths? ๐Ÿ˜ตโ€๐Ÿ’ซ

chilly surge
#

Maybe invisible characters?

runic linden
#

Well apparently ๐Ÿ˜„

chilly surge
#

Can always do a trim before comparison but eh, still sounds kind of brittle relying on magic values.

mellow sigil
#
Not successful comparing Speakers: Froggo
"Not successfull comparing " + speaker

so the value of speaker is "Speakers: Froggo" (16 characters)

runic linden
#

LOL

#

I am so dumb

#

Thanks

#

Just printed out the first string in my console char by char and came to the same conclusion, which I should have done before asking here. Thanks for helping though.

mellow sigil
#

I usually debug like this when checking why strings aren't the same:

Debug.Log($"Not successfull comparing '{speaker}' to '{_speakers[0].GetName()}', {speaker.Length}, {_speakers[0].GetName().Length}");
vestal arch
#

tip: separate the logs instead of having them be a single message, so they come out vertically aligned and it's easier to spot differences that way

mellow sigil
#

The quotes then tell if there's extra whitespace etc

static matrix
#

is there a ui element for hover?

leaden ice
#

detecting hover is done with a custom script with IPointerEnterHandler/IPointerExitHandler OR with an EventTrigger component.

static matrix
#

ah, ok

urban light
#

My trees are starting to look like this. Do you guys know what the issue might be?

heady iris
#

how are these trees being rendered?

#

are they part of a Terrain?

#

if so, do they have LOD models?

urban light
#

They are part of the terrain, and URP i think

#

And whats an LOD...

heady iris
#

LOD stands for Level Of Detail

#

You create multiple models with different quality levels

#

nearby trees use the highest quality model; distant trees use a super chunky one

#

In this case, though, I think this is a problem with your textures orw ith the tree shader

#

notice how that huge box perfectly encapsulates the actual branches

#

well, almost perfectly

#

It looks like the shader is rendering areas that should be transparent.

urban light
#

Hmm how would I fix that?

heady iris
#

show me the material you're using on the tree

urban light
heady iris
#

that's the bark, not the leaves

#

i forget which shaders you're supposed to use on terrain trees in the URP

urban light
urban light
#

it worked tyty

heady iris
#

programs like Blender and Substance Painter will fill transparent areas with the nearest non-transparent pixel

#

this prevents weird color problems if you downscale the image

#

or if you sample slightly of bounds

urban light
#

Actually I just applied it to all of my leaves, and now

#

Some are still weird

leaden ice
knotty sun
#

!learn

tawny elkBOT
#

:teacher: Unity Learn โ†—

Over 750 hours of free live and on-demand learning content for all levels of experience!

leaden ice
#

Hard work and determination

knotty sun
#

And I mean !learn

tawny elkBOT
#

:teacher: Unity Learn โ†—

Over 750 hours of free live and on-demand learning content for all levels of experience!

vestal arch
#

so what do you want to do?

leaden ice
#

To get good at Unity, you will need to spend a lot more than 750 hours

vestal arch
#

have someone make one for you?

knotty sun
#

then don't your choice, there is no such thing as a free lunch

vestal arch
#

try searching 2d tutorial

leaden ice
#

top down is just a camera angle my friend

#

or really

#

for 2d, it's just a mindset

#

and an art style

vestal arch
#

your choice

#

the unity learn is the only one this server can officially recommend, given that this is an official server

#

but the important thing is, you have to learn (as long as it's a quality source)

#

doesn't matter too much from where

#

if youtube fits better to your learning style, go ahead

knotty sun
#

if you think you can learn everything you need to learn from a single yt tutorial you are very much mistaken, but, you do you

craggy oyster
#

theyre saying you might be able to find a tutorial on copying things step by step but you wont know how to do anything which isnt really "making a game"

vestal arch
#

depends on the tutorial and the learner tbh

#

if you have the foresight to care about understanding rather than just copying, you'll figure out which tutorials are the good ones yourself and you'll be able to utilize their full content

craggy oyster
#

i have been making games on unity for 4 years now and I would say I actually started learning just this past year because prior to that i would just watch youtube videos

vestal arch
#

generally i would recommend text-based guides more but even the official source has a ton of videos so it's kinda hard to stick to that

#

easier to come back to reference, whether it's 5 minutes or 5 months after you read it

#

it's not a crime to ask for help lmao

craggy oyster
#

also if youre just starting out totally watch youtube videos and tutorials

#

but actually try to understand and try playing around with what youre learning

spring creek
craggy oyster
#

i find unity learn to be way too boring to watch

#

idk if anyone else feels the same

chilly surge
#

Life isn't always fun.

craggy oyster
#

i think it was because i was watching the lower level tutorials though

craggy oyster
#

but more of Im not learning anything new and and im not entertained

craggy oyster
spring creek
#

If you aren't learning anything new, don't do that part of the pathway

craggy oyster
#

i tried checking it out and i stopped because i got bored

#

i didnt know they had higher level tutorials

#

until recently

knotty sun
#

If you want to be entertained, watch Netflix

craggy oyster
#

this guy man.

#

Yea just go ahead and disregard the explanation and try to sound smart

vestal arch
knotty sun
#

I think you are confusing entertaining with engaging, that is all

vestal arch
#

he didn't mention either

rigid island
craggy oyster
#

ive felt extremely entertained with many tutorials before idk what you mean

vestal arch
rigid island
#

huh never seen that on learn

vestal arch
#

the majority are quite good, i just... don't know how i feel about the minority that aren't

craggy oyster
#

all i was trying to say was i tried unity learn a long time ago and i wasnt really learning anything because i was at a higher level than i thought i was

spring creek
#

I have yet to see a better way to learn unity

craggy oyster
#

or has brackeys been black listed on this server

#

lmao

spring creek
vestal arch
rigid island
craggy oyster
rigid island
#

code monkey is worse becuse they imply what they do is "clean code"

#

meanwhile all their shit depends on watching other videos of his to do 1 thing
so all the code is scattered all over the place

craggy oyster
#

but they have a lot of good tutorials on just "setting things up" but its definitely true that youre not really learning much

chilly surge
#

I've only watched a few of Brackey's videos when I just started Unity years ago, their videos are almost the definition of "teacher reading texts off of PowerPoint without explaining anything" on top of all the bad practices they teach.

spring creek
craggy oyster
#

ok thats a little too far from you guys

vestal arch
#

i feel sometimes one of the best resources in game dev is whatever genre freya holmer makes

craggy oyster
#

theyre not that bad code monkey has great overviews on c# in general for beginners

rigid island
craggy oyster
#

I leveled up my coding skills from a codemonkey c# tutorial once but I have never watched any of his other videos

spring creek
#

He is very personable. Great presenter.
But no, experienced programmers all hated him ime.

His advanced stuff is good. Just the beginner stuff is terrible

lunar python
chilly surge
rigid island
#

but i cant fault them for that cause i know personally how making videos can be a weird grind

#

you have to show useful information in a limited time (peoples attention spans are small)

#

mine expect you to already know the basics and I'm just showing neat features that I personally find useful

spring creek
chilly surge
#

Sure, which is why I don't think YouTube as a platform is a good medium for learning, because videos posted by the content creators who make a living out of them, are optimized to make money, not optimized to teach.

lunar python
#

you could read some articles made by random guy and it's very good

craggy oyster
#

speaking of this topic does anyone have any reccomendations on learning shaders

spring creek
chilly surge
#

The actual good learning videos? 40 mins long of someone with 5k subscribers who post a video every 2 years, no background music fancy transitions, no camera, just talking and straight to the point and in depth.

#

Learning really just can't be that fun.

craggy oyster
#

definitely will check it out in my free time

rigid island
# craggy oyster speaking of this topic does anyone have any reccomendations on learning shaders

there are a few youtubers that make good videos strictly shaders though
like
https://www.youtube.com/channel/UClgoE54W_4rX7jzZGiCmrXw

vestal arch
chilly surge
#

Typo ๐Ÿ˜“

vestal arch
#

i'd like to imagine a video with a vsauce voice echoing directly into your head

lunar python
craggy oyster
craggy oyster
#

maybe now i will be able to

rigid island
#

shes good but tooo mathy for my taste
thats a good thing though, shes goes into the actual math of the whole thing but I don't got patience for it lol

vestal arch
wispy juniper
#

I'm trying to implement custom Bloom effect in Custom Render Feature, totally bypassing URP's post-processing stack. I've started from the end of pipeline - from tonemapping.
So I've created simple render pass that grabs _CameraColorAttachmentA and tonemaps it into camera color target through custom shader. But I've encountered couple problems.

  1. Hardcoding _CameraColorAttachmentA does not seem reliable, but I can't find a workaround
  2. I see results of my render pass in frame debugger, but UPR's FinalBlit pass always overrites it in the end. I needed to push RenderPassEvent to AfterRendering+500, but I'd like to get rid of FinalBlit totally as my tonemapping fulfills all it functions anyway
lunar python
#

welcome to shaders, you need math bro

#

nowhere to hide

craggy oyster
#

my math level is intermediate algebra

rigid island
craggy oyster
#

computer science in uni will probably fix that though

lunar python
#

no

#

cs in uni is kinda basic

craggy oyster
lunar python
#

there are good math course in uni

#

if you want to ruin your life

craggy oyster
#

i actually enjoy math once i understand it

#

the problem is i dont understand it ๐Ÿ’€

vestal arch
#

relatable

tawny gale
#

I'm working on creating a highly modular game that allows players to easily create mods with new levels. However, I've encountered an issue with asset bundles and Addressables โ€“ they don't seem to support the inclusion of code content, and as a result, the code isn't compiled when building the bundles. I'm looking for alternative approaches to address this challenge. Does anyone know of a method besides compiling the code separately, or have any other ideas to overcome this problem?

pulsar holly
rigid island
#

dont think eulerAngles eveer goes to - numbers does it ? @pulsar holly

#

ok yeah confirmed it, had to be sure lol

#

you cannot cause I remember having to do something like i found on internet
float angle = transform.localEulerAngles.x; angle = (angle > 180) ? angle - 360 : angle;

#

so basically it goes 0 to 360

craggy oyster
rigid island
#

really? thats the reason why I didn't go for it

#

mainly scared of advanced calculus and shit, i rather spend time in a desert

craggy oyster
#

but i want to learn calculus either way

vestal arch
rigid island
craggy oyster
#

i think hes trolling though comp sci is legit calculus

fervent furnace
#

begin with machine learning stuff, full of vector matrix calculus

craggy oyster
#

and like web development and backend development

rigid island
#

they just said they never been in uni

rigid island
craggy oyster
#

not just want without the effort

lunar python
#

i already finished calculus in highschool

vestal arch
craggy oyster
rigid island
#

its more like...backend developmenet, for like a nasa computer or something..

#

if you see what they did for the apollo computers, your brain melts

#

they literally used strings as wires, shit was incredible .

craggy oyster
#

i aim to reach that level someday

craggy oyster
#

keep me on monobehaviors ๐Ÿ˜ญ

vestal arch
#

wait till you see the dibehaviours

lunar python
#

cs in uni depends on what uni you go to

leaden ice
#

Sounds like a bug possibly, I'd report it as such.

remote fractal
#

my game has alot of spells, each of them are diverse. making a template for them is just not possible.
do i have to write code/make different scripts for each one of them or is there another way?

leaden ice
#

Spell/Effect/Ability systems can be quite complicated, it really depends on the scope and complexity of your game/combat system

#

You will almost definitely have to write some custom code for special effects

#

But you can generally reuse code for generic effects like "damage a unit"

remote fractal
#

aighty
time to run marathon

#

ty

hollow hound
#

How can I disable default collision detection/calculation done by Physics2D? I have custom logic for handling that and default collision affects performance

leaden ice
#

If you don't want to use the built in physics at all, you should remove all physics components from your objects

remote fractal
leaden ice
#

(or just setting the interaction in the matrix in settings)

remote fractal
#

yea taht too

hollow hound
#

Seems like it detects collisions and calculates physics in addition to custom logic, basically doing the same thing again.

glossy mortar
#

why is my gameobject not pointing towards the mouse?

mousePosition = Camera.main.ScreenToViewportPoint(mousePosition);

Vector2 direction = new Vector2(mousePosition.x - transform.position.x, mousePosition.y - transform.position.y);

transform.up = direction;```
leaden ice
#

transform.position is in world space

#

you need to convert the mouse position to world space

#

ScreenToWorldPoint is what you want

hollow hound
glossy mortar
leaden ice
#

you can use whatever ContactFilter2D you want for a cast

leaden ice
#

read what I wrote

glossy mortar
#

ah

#

It works now. I was just being stupid.

opaque forge
#

Guys I'm instantiating houses along edges of a polygon but obviously they will hit each other on the corners, I tryied using Physics.Checkbox to check if there is smth already without success. Here is how I use it:

 //move instantiation area to the left``` 
all the houses have a mesh collider attached to them, but it seems that this doesn't work. Can someone tell me if I'm doing something wrong or if there's a better alternative?
rigid island
#

are you using Unity 2022 ?

opaque forge
#

yess 2022.3

rigid island
#

they have a neat feature to debug Casts/physics checks

opaque forge
rigid island
#

i wonder if it works for Checkbox

opaque forge
rigid island
opaque forge
#

thx a lot I will look into it~!

rigid island
#

oh yeah it does say in manual too
The options are:

  • Overlap queries
  • Check queries
  • Cast queries
#

so yeah check should work , you will be able to see it in playmode

#

start by the basics, see visually if its correct rotation/positions etc.

opaque forge
#

its weird because here you can see it clearly overlaps, but nothing in my checkbox

leaden ice
#

Also when you say... "polygon" what do you mean exactly?

#

PolygonCollider2D is a 2D collider if that's what you mean

opaque forge
leaden ice
#

Same frame

#

Unity runs in frames

#

each Update is a frame

#

it renders once per frame

opaque forge
#

I run it in start

spring creek
leaden ice
#

that would explain things

opaque forge
#

ahhh yes it is

leaden ice
#

You will need to run Physics.SyncTransforms() before every physics query you make

#

otherwise the physics engine will not know about your colliders or where they are

#

because that normally happens during the physics simulation step

#

or rather, between every collider spawn/move/rotate and doing a physics query

opaque forge
#

wow ok

opaque forge
west socket
#

Hello
I have a problem with the FBX exporter.
I try to export a skinned mesh, with a skin hierarchy, and the materials are exported without the textures.
I tryed to add the texture to the export, but same thing, it's ignored.
If i only export the texture, unity respond that nothing was exported

UnityEngine.Object[] objects = new UnityEngine.Object[] { exportObj, m_currentModel.texture };
ModelExporter.ExportObjects(m_exportPath, objects);

All the exported objects are created on the editor, and destroyed afterwards.
Is there a way to export a texture on an FBX file ? The doc say so, but i can't do it.

magic harness
#

Alright guys, i'm currently working in an RPG and as such, my mouse will have to be able to do a bunch of different things like:

  1. Move
  2. Target an Enemy (also do we want to auto attack like ragnarok)
  3. Cast a skill if there is one selected
  4. Pick up loot
  5. Interact with an NPC

So.. i'm basically using the event system interfaces like IPointerHandler, IPointerDown to detect clicks in different objects, but the problem is, regarding movement, i need to detect the point where it has been clicked, so i do a raycast, but now i cant really select enemies anymore. Can someone give me some lights on how to get this done?

leaden ice
#
foreach (var location in myList) {
  Instantiate(thePrefab, location, Quaternion.identity);
}``` Just something like this, no?
#

Or you mean you want the spawned object to walk along the list or something

civic isle
#

could you explain

knotty sun
#

And, please, write in full sentences

civic isle
#

lol

#

i would like the positions i have in the inspector on my object to carry over to the prefabs i instantiate

leaden ice
#

or instance.locations = new(locations);

#

or just instance.locations = locations; if you promise never to change the list ๐Ÿ˜›

civic isle
#

that was very fast

leaden ice
#

The basic idea is just... pass the list to the instance

civic isle
#

thank you

leaden ice
#

the basic idea is just pass the information to the newly instantiated object

civic isle
#

i have the instantiating and the list on separate scripts is that an issue

leaden ice
civic isle
#

i should understand that

ashen jasper
#

question is there a way for a player to follow a spline at a certain point

#

Its only for a loop

craggy oyster
ashen jasper
spring creek
civic isle
#

yeah i dont get it

lean sail
tender plume
#

thanks

craggy oyster
#

and wheres the lists you want to be the same

civic isle
#

that is in zigzag

#

accsess it with zizag.targets

craggy oyster
#

and you want these objects ur spawning to have that list?

civic isle
#

yes

craggy oyster
#

do they have a script attached to them?

civic isle
#

they have the zigzag script attatched

craggy oyster
#

ok and wheres the original list that you want to have these objects copy from

civic isle
#

the zigzag script

#

unless if im not understanding

#

public List<Transform> targets = new List<Transform>();

#

this is in the script and is what i want to use

#

when they are instantiated, they spawn with the list, but the list is blank

craggy oyster
#

assuming you want all these gameobjects list to change when you change the list ever

#

a list is a reference type so if you change one they will all change just keep that in mind

rigid island
#

where do you do that, you're not doing that in the code anywhere

#

they literally give you script exactly and you copied different lol

civic isle
#

erm

#

they are instantiated

#

cant put the positions on the prefab itself

#

i tried making the positions themselves into prefabs and then i can put them in, but that dosent work

craggy oyster
#

just do obj.getcomponent<Zigzag> and set the the list to anything you want

spring creek
#

Yes

civic isle
#

its over

spring creek
#

Captilization is important

civic isle
#

okay yah it works bnow

rigid island
#

Aslo you dont need to do GetComponent if you write it like Praetor wrote it

dusk apex
#

The ide should have provided you the correct method to call.

rigid island
#

You can spawn it directly as Zizag object

#
Zizag obj = Instantiate
obj.targets = etcc.```
ah yes `prefab` should be Zizag, You might need to drag object inside again inspector or might say mismatch.
dusk apex
#

Reference it as the correct type, drag the game object with said component type to the serialized field in the inspector and instantiate an instance (referenced as the actual type) without needing to call get component - profit.

craggy oyster
#

getting him to use getcomponent so he doesnt get overwhelmed

rigid island
#

TryGetComponent is better than GetComponent

#

is somehow its case its not found you dont get NullRef

craggy oyster
#

true but i dont think he understands an out

civic isle
#

confirm i dont know the meaning of alot of the words mentioned

#

very nice to try to help me

rigid island
#

yes the words sound scary but you're not doing anything crazy

dusk apex
#
//field definition
public Zigzag prefab;``````cs
//use case
Zigzag zz = Instantiate(prefab, ...);
zz.targets = ...
...```
rigid island
#

in simple terms , you can Spawn something directly as that Component instead of a generic GameObject

#

every Component has access to their holding gameobject anyway

gray mural
#

Because of the T Instantiate<T>(T original) where T : Object returning the T passed in the 1st parameter, making it able to spawn an Object, or any class derived from it

rigid island
#

yeah was gonna say that function is Object

#

not to be confused with the C# Object

#

they are different (hence why you cannot use ?? or ? on unity objects)

gray mural
#

Yes, there is a need to specify the namespace if both System and UnityEngine are used

civic isle
#

the console says that the object i want to instantiate is null

craggy oyster
#

check if u assigned it correctly in inspector

civic isle
#

for public zigzag prefab

gray mural
#

And that's the first thing you do when getting a NullReferenceException

civic isle
#

are u saying i should reference the script

gray mural
gray mural
#

They told you to check whether the object is assigned, obviously not, in the Inspector

civic isle
#

chillax

#

the object is assigned but its a script

#

Have i misinterpreted

craggy oyster
#

show your code again

civic isle
#

so what is supposed to happen when the zigzag script is referenced and then i instantiate it

craggy oyster
#

i think youre up to some naughty stuff

civic isle
#

lol perhaps

rigid island
civic isle
#

sorry about everything being named zigzag

naive swallow
craggy oyster
#

i see

naive swallow
#

Okay, and after changing the type of prefab, did you drag the reference back in?

civic isle
#

the zizgag script is infact placed in the editor

naive swallow
civic isle
#

i was using a crab arm whilst prodotyping

naive swallow
civic isle
#

imagine if i was competent like how fire would that be

#

so now the error is that Object reference not set to an instance of an object

#

and when i click on that

civic isle
#

it send me to StartCoroutine(InstantiateObjects());

fervent furnace
#
zz.targets = zigzag.targets;
```this line?
naive swallow
civic isle
#

i ran it and it still does that

naive swallow
leaden ice
#

this code assumes you also have a ZigZag attached to the same object as SpawnZigazag

#

do you?

civic isle
#

if you mean zigzag script then no

#

spawnZigZag is on a gameManager

leaden ice
#

then that's why it's not working

craggy oyster
#

you wouldnt even be able to assign it then

leaden ice
#
zigzag = GetComponent<Zigzag>();```
#

this expects it on the same object

civic isle
#

my bad

leaden ice
#

So it's unclear what you're trying to do with that

dusk apex
#

Or just reference it through the inspector

rigid island
#

yes why are you copying list from a zizag on spawner ?

craggy oyster
#

i think if we asked him what he was trying to achieve this wouldve been over 1 hr ago

rigid island
#

also be aware when you do = you're assinging the same list to all of the ones spawned

#

since lists are reference types, you're passing the same list around

#

if you were to modify an entry, they all get the change (idk if u would want that or not)

civic isle
#

i think i would like all the instantiaed prefabs have the same list

rigid island
#

the List should just be on a scriptable object but yeah that gets complex..here

#

cause that would allow you to spawn zizag already with that list in prefab

civic isle
#

i have moved the list to the same object now

#

they are together

#

there is an error on line 27, zz.targets = zigzag.targets;

leaden ice
#

"an error" is vague

civic isle
#

object reference not set to instance of an object

leaden ice
#

then you still haven't managed to actually get the two scripts on the same object

#

or you have another copy of this script where it's not there

civic isle
#

referencesInScene say there are both only on that

#

restart

#

I would like to instantate gameobjecs and have them move towards the positions defined in the list

leaden ice
#

Yes we know that

civic isle
#

when i did this with the gameObject which isnt instantiate it worked fine, but when instantiating more they would lack the positions on the list

leaden ice
#

You're going to need to show some screenshots of things

civic isle
#

Now that both scripts are on the gameManager, it instantiates the gameManager instead

leaden ice
#

because you're being very vague

craggy oyster
#

oh lawd

leaden ice
#

instead of to your prefab

#

do you even have a prefab?

#

Sounds like you don't

#

For reference, a prefab would be an object in your Project folder

civic isle
#

i do have a prefab

leaden ice
#

not in the scene

civic isle
#

what should i screenshot pls

simple egret
#

And post your current code, if you put the script on the Game Manager and it instantiated a copy of the Game Manager, you did Instantiate(gameObject) at some point

#

Yep looks like you dragged the GameManager in, instead of your prefab

civic isle
#

that is the ZigZag script named prefab

leaden ice
#

that's not a prefab

#

prefabs live in the project folder

#

but honestly - if you wanted to just put that thing elsewhere in the scene, you could just instantiate it and it will copy those references automatically

simple egret
#

If it was the prefab, that field would have said "crab arm (Zigzag)"

leaden ice
#

no need for the code that copies anything at that point

naive swallow
#

Why did you assign this object as the prefab

#

What is line 26

craggy oyster
civic isle
#

zz.targets = zigzag.targets

leaden ice
craggy oyster
#

youre spawning the spawnmanager

civic isle
naive swallow
leaden ice
simple egret
#

I don't think they know what they're doing, to be fair

leaden ice
#

They do not

civic isle
#

fact

craggy oyster
#

no shame in that youll get in with practice

naive swallow
#

Definitely. The issue is we assumed someone posting in general instead of beginner had any clue about logic and navigating the program

leaden ice
#

You either:

  • Just Instantiate from an instance in the scene and it works automatically
  • Have another copy in the scene to copy the list from and spawn a prefab (and reference that other copy properly) and then copy the list.

But you're kind of half doing one and half doing the other and it doesn't work that way

dusk apex
civic isle
#

yeah i thought i wasnt a begginer no mo

fervent furnace
#

once you start coroutine the ienumerator runs until the next yield statement iirc
btw fix your set up first

craggy oyster
civic isle
#

lol

#

yeah me

craggy oyster
#

you are definitely a beginner i would say im definitely a beginner too

civic isle
#

well if you are then i am

craggy oyster
#

if you are new to coding in general

#

i reccommend understanding an object oriented programming language first

#

get some basics down before you start making games

civic isle
#

i am not that new

#

i have never done anything with prefabs or instantiating them tho

craggy oyster
#

time != skill

civic isle
#

wait should i go back to my original script lol

fervent furnace
#

so you are new to unity engine

craggy oyster
#

if you dont know how to use prefabs you definitely should watch the beginner unity learn course

civic isle
#

is my original script fine to build off or should i use the new one

naive swallow
#

what is the end result you want to achieve

civic isle
#

i would like the instantiated objects to have a list of transforms on them in the inspector

naive swallow
#

what is the purpose of the list

#

Where does its data come from?

civic isle
#

i will @ you when i am ready to respond

robust whale
#

How can I write the decrease if it is running and the increase if it is not running in a short way?

if (isRunning) {
 stamina -= Time.deltaTime / 4f;
}else{
 stamina += Time.deltaTime / 4f;
}
leaden ice
#
stamina += (isRunning ? -1 : 1) * Time.deltaTime / 4f;```
#

but this is kinda weird

#

because I would normally expect to be able to have different consumption and regeneration rates

#

Normally I'd do something like:

float changeRate = isRunning ? ConsumptionRate : RegenerationRate;
stamina += changeRate * Time.deltaTime;```
#

and ConsumptionRate can just be -0.25f and RegenerationRate can just be 0.25f

simple egret
#

Cursed alternate universe C# answer: stamina (isRunning ? -= : +=) Time.deltaTime / 4f

gray mural
# robust whale That works

May also be simplified to this in your case, but I would recommend having a variable for 4f.

stamina += Time.deltaTime / (isRunning ? -4f : 4f);
leaden ice
robust whale
robust whale
leaden ice
gray mural
robust whale
leaden ice
#

Here, the ideal form:

Func<float, float, float> addFunc = (a, b) => a + b;
Func<float, float, float> subFunc = (a, b) => a - b;

Func<float, float, float> func = isRunning ? subFunc : addFunc;
stamina = func(stamina, Time.deltaTime / 4f);```
robust whale
gray mural
#

it takes float and float, and returns a float

robust whale
#

Haa okey ty

gray mural
#

(float, float) => float

leaden ice
#

it would be cool if you could say:

Func<float, float, float> addFunc = float.+;```
naive swallow
#

All right this is getting a bit too pythonic for my blood I'm out

solar wigeon
#

hello, can someone explain why my dash stops working after 3 dashes and the dash count stays at 1 eventhough its supposed to reset to 2 after 3 dashes

leaden ice
#

Well for one, this looks like a nightmare:

    private void LateUpdate()
    {
        if (dashCD1 == false)
        {
            Invoke("Dash1", 3);
        }
        if (dashCD2 == false)
        {
            Invoke("Dash2", 3);
        }
    }```
#

Also why is dashCount a float and not an int?

#

Anyway DashCD2 doesn't seem to be used anywhere

#

I mean you certainly set it true and false in a couple places but, it doesn't actually seem to be used in your dashing logic at all

#

This all seems kind of overcomplex to me anyway

solar wigeon
#

can u give advice what to do ?

leaden ice
#

I would do something much simpler

#

no Invokes etc

solar wigeon
#

wow i never thought of something like this thanks will take this advice

leaden ice
#

edited** ^

solar wigeon
#

but if you look in the code i want my UI to go open and close every time dash like in ultrakill

#

or in ghostrunner

leaden ice
#

I don't know those games but that's easy enough to add on.

#

that would be part of the actual dashing code

solar wigeon
#

but i dont know where i can add the on and oof for the ui

leaden ice
#

but also I'm not entirely sure what you mean by this so maybe some screenshots or video would help

solar wigeon
#

k let me send