#💻┃code-beginner

1 messages · Page 109 of 1

vocal thorn
#

i just dont know how to fix it

vocal thorn
#

My otters are visible

#

but their coordinates are completly jumbled up

ivory bobcat
#

Have you looked into coroutines yet?

vocal thorn
#

this is where they are atm (I stopped the game, the coords keep on changing)

vocal thorn
ivory bobcat
#

If not, consider investing some time into that to substitute your delay feature from sleep

vocal thorn
#

thats the plan, however right now the coordinates are my priority, i can't tell why they're moving wrong.

patent compass
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

ivory bobcat
#

Else the game/while-loop will immediately end (an undefined behavior which no amount of bandaid can help)

vocal thorn
lucid atlas
#

hello every1, im new

vocal thorn
rare basin
eternal falconBOT
rare basin
#

also don't use print()

lucid atlas
#

what should i do now🥺🥺

rare basin
#

ues Debug.Log instead

lucid atlas
#

can some1 show me what should i do🥺🥺

vocal thorn
rare basin
lucid atlas
ivory bobcat
wild cargo
# lucid atlas oh my apologize

Install Unity, try to make a simple game, when you encounter an error google first and if you find no results then post here

vocal thorn
#

but that shouldn't change the fact that the coords change...

vocal thorn
rare basin
#

and pls adapt your formating and naming conventions

#

to one standard

#

it is unreadable

ivory bobcat
lucid atlas
rare basin
#

when you will have an issue with particular code/system/mechanic then you can ask here

#

also unity is C#, not pure C

ivory bobcat
eternal falconBOT
lucid atlas
vocal thorn
vocal thorn
rare basin
vocal thorn
ivory bobcat
vocal thorn
#

I'll send the updated version

vocal thorn
#

Okay, understood. That's the reason why the Coroutines exist right?

#

I just read up on that

#

A slightly random question, but if anyone knows Java, do you have any Tips on how to use that knowledge (other than Algorithms) in C#?

wild cargo
#

Common sense basically

rare basin
#

as any other language

whole isle
gaunt ice
#

Dont always use class
java have no struct....

whole isle
#

is mine wrong cause in the videio they have asset

gaunt ice
#

please watch(?) the video more carefully

whole isle
#

oh is it not in the IEnemurator

vocal thorn
# rare basin it's just different syntax

I moved from Python to Java this year, and it was quite simple, but a few changes. Java to C# is relatively close from Syntax (in my opinion ofc), however I just can't quite grasp everything like with the Java transition, I think that might be my main issue.

ivory bobcat
# whole isle

While loop is outside of the coroutine or any function which was invalid

vocal thorn
whole isle
#

im facing this error now

ivory bobcat
whole isle
#

do i cahnage it to blueslime

ivory bobcat
#

Hint: Something's different

#

Type name = stuff

north kiln
#

The code is completely different in those areas

ivory bobcat
north kiln
# whole isle

The name of GameObjects do not relate to how you write code

vocal thorn
whole isle
#

k thx imma try fix it

ivory bobcat
vocal thorn
whole isle
ivory bobcat
north kiln
#

Among some other basic and important differences

#

Just compare the two?

whole isle
#

like this line?

gaunt ice
#

please compare your code and the code video shown char by char

ivory bobcat
whole isle
#

fixed that line

vocal thorn
#

thank you though!

whole isle
#

fixed it thx guys

north kiln
#

It would be much easier to write if you tried to understand why you were writing it catcrymic

vocal thorn
north kiln
#

Yes

#

You have 3 instances of the Otter class and they each run their own coroutine

vocal thorn
#

They're GameObjects, does that make a difference?

vocal thorn
north kiln
#

You are thinking wrong either way

vocal thorn
#

Okay. Do you mind explaining? I'm sorry for the inconvieniece

north kiln
#

The code executes each coroutine until their first yield, and then the next frame Unity resumes at that point of each coroutine if the yield has passed

#

Nothing executes in parallel/simultaneously, but there will be 3 coroutines running at once

vocal thorn
#

Okay Okay.

north kiln
#

You can use the debugger and step over the code for the first execution and see where it goes. Though the next frame execution jumps to the yield from unmanaged code when Unity calls it

vocal thorn
#

Just so that i know I'm understanding it correctly:
the yield in one Coroutine has nothing to do with the yield in a different one, for example:
CoRou 1 -> yield return null;
CoRou 2 -> yield return new WaitForSeconds(5);

it wouldn't wait for those 5 seconds so that it CoRou could move on. Because It's not connected.

north kiln
#

They are separate state machines, yep

vocal thorn
vocal thorn
rare basin
#

"how to debug in Unity using a debugger"

vocal thorn
#

Thank you all so much for your help.

north kiln
#

There's good resources pinned about debugging with VS. the video series is quite thorough

vocal thorn
#

Thank you!!! I'll def look into it

sour fulcrum
#

bit of a weird question, I have a terrain that im loading into a scene OnSceneLoaded

#

but due to its resolution and trees and such it seems to drawcall bomb the build into crashing

teal viper
#

That wouldn't crash the build. At least not directly.

sour fulcrum
#

is there a built in way to gradually stream this in or can i like professionally unity to brace for impact

teal viper
#

Indirectly you could be running out of vram, but I highly doubt it.

#

Inspect the player/ crash logs. There must be some clues to what caused the crash.

sour fulcrum
teal viper
#

The generic solution is: investigate the crash and eliminate it's cause.

#

There's no more generic than that.

rare basin
#

do you have any code to share?

#

as this is a code related channel

teal viper
#

Or logs.👀

rare basin
#

anyway, use addressables on that and recude draw calls by batching, making atlas materials, merge meshes together into one

#

there is a lot of optimization you can do

#

do LODs etc, many drawcalls = cpu bottleneck

sour fulcrum
#

I would love to use Adressables here but as it’s mod related I cannot

I’ve been looking through the logs a ton and I can’t find anything that points towards the crash specifically that doesn’t also occur on a build that successfully loads. I can add logs to places but aside from the function where i create it I don’t know where specifically unity crashes between then and the crash, will post a log but ofc it will be missing a lot of context

rare basin
#

without any context/data/logs/errors we cannot help you, espeficially in a code related channel 😉

sour fulcrum
#

no forsure

#

i can send partial code and crash log

rare basin
#

just debug the issue, try to load smaller terrain

#

see if the problem is indeed in the big terrain itself

#

then maybe async load it piece by piece

teal viper
#

Or crash report.

rare basin
#

what do you even my by crash

#

does the app just fereze and dont respond

#

or do you have unity crash message?

sour fulcrum
#

game freezes before crashing, i do not get a crash message

#

not avoiding btw in the process of getting info

teal viper
#

Could be an infinite loop then

rare basin
#

so this is not a crsah

#

either infinite loop, or you load extremaly insane amount of data (which i doubt it)

teal viper
#

Connect the debugger to the build and break when it freezes(it might break automatically too)

sour fulcrum
#

Player.log with crash
https://hastebin.com/share/puqiciciji.yaml

This is the code that instantiates the terrain on OnSceneLoaded (it spawns the prefab, moves all its root objects to the scene and turns itself off)

                        GameObject mainPrefab = Instantiate(Terminal_Patch.newMoons[StartOfRound.Instance.currentLevelID].MainPrefab);
                        if (mainPrefab != null)
                        {
                            Logger.LogInfo("Moving Custom Moon To Scene : " + scene.name);

                            SceneManager.MoveGameObjectToScene(mainPrefab, scene);
                            mainPrefab.transform.DetachChildren();
                            mainPrefab.SetActive(false);

this is the end of the function and crashes after this, depending on the terrain settings

teal viper
teal viper
sour fulcrum
# teal viper Sure

didnt know that! i'd love if you could point me in the right direction for that

sour fulcrum
sour fulcrum
#

tried googling but couldnt find any solid answers

teal viper
#

From the logs, it looks like it's something in the hdrp render render loop, but it's hard to say anything specific, since there are debug symbols missing.

sour fulcrum
vocal thorn
#

Hello- it's me again. I think I have the Coroutines figured out, the only thing I can't right now is something fairly basic. My otter is always at the wrong coords.

    IEnumerator randomappearance(GameObject selectedOtter){
        Debug.Log("Coroutine Started");
        selectedOtter.gameObject.SetActive(true);
            var hInput = Input.GetAxis("Horizontal");
            var vInput = Input.GetAxis("Vertical");
            int xlocation = Random.Range(1,3);
            Vector3 newx = new Vector3(vInput,hInput,0);

            if(selectedOtter != null){

                if(xlocation == 1){
                    newx = new Vector3(vInput,hInput,0.7f);
                    Debug.Log("reached location changer start 1");
                    yield return null;
                }
                else if(xlocation == 2){
                    newx = new Vector3(vInput,hInput,1.4f);
                    Debug.Log("reached location changer start 2");
                    yield return null;
                }
            selectedOtter.transform.position = newx;
            yield return new WaitForSeconds(Random.Range(0,3));
            }
    }

When looking at the coords that I want, they're completely off...

ivory bobcat
#

Log the position

#

Place a break point and verify with the inspector

teal viper
ivory bobcat
#

Local position would be what you'd see in the inspector.

vocal thorn
#

the position i want is (0,0,1.4)... It's slightly off.

teal viper
ivory bobcat
#

Are you certain they're the same object?

vocal thorn
ivory bobcat
#
Debug.Log($"{selectedOtter.name} has a position of {selectedOtter.transform.localPosition}", selectedOtter);```
vocal thorn
#

okay

ivory bobcat
#

Place it before the yield statement but after assigning position

vocal thorn
#

just did!

ivory bobcat
#

What did it print?

#

What was highlighted yellow when selecting the debug log?

vocal thorn
#

im starting to see the issue

#

its using the parent, not the children

ivory bobcat
#

So you've got a clearer image of what's going on now.

vocal thorn
#

yes

#

not sure how to fix it though

#

one second i think i might have found the issue

#

nevermind

#

still cant find the issue

#

i know what the issue is, im not sure how to resolve it

ivory bobcat
vocal thorn
#

what edit?

ivory bobcat
#

The edit to the code I provided.

vocal thorn
#

Ah sorry, i didnt see it

ivory bobcat
#

It should be the correct object with the edited code

#

Previously it was analyzing whoever was managing the three

vocal thorn
#

Yes! It's selecting the Children now

ivory bobcat
#

So is the info correct?

vocal thorn
#

is there a way to get the axis of the children instead of the parents too? I think thats whats happening,

ivory bobcat
#

Maybe you meant to move relative to local position

vocal thorn
#

this is how im getting the coordinates at the moment

#

could i put a selectedOtter.Input.etc()?

ivory bobcat
#
...localPosition = newx;```
ivory bobcat
vocal thorn
vocal thorn
ivory bobcat
vocal thorn
#

Ah, okay I see my error

#

I think the parent is moving with them because the coords on the children are looking great, but they're landing in the middle of nowhere

ivory bobcat
#

The inspector position would be the local position of the object relative to it's parent. If you want their world position to be at the specific coordinates, use position like before.

#

The inspector value will not be what their world position is if they're child to another object not at (0, 0, 0)

vocal thorn
#

is there a way to lock the parent into place?

#

i found a solution

#

if anyone else ever has this issue

#

just add a rigid body and put all constraits on

rare basin
vocal thorn
rare basin
#

IEnumerator randomappearance(GameObject selectedOtter)

#

that is not a propper funcion naming

#

infact it makes me not even wanting to read the rest of the code 😄

rare basin
vocal thorn
#

I forgot about the functions

vocal thorn
static cedar
#

Microsoft seems to hate snake_case.

vocal thorn
static cedar
#

Basically:

  • Classes, Structs & Functions: PascalCase
  • Getters/Setters: PascalCase
  • Variables: camelCase
  • Private field variables: _case (I don't think people hear this often but i'm pretty certain Microsoft suggests this and can see this on some of their standard libraries.)
  • Interfaces: IPascalCase (Yes, with the I at the start.)
  • Attribute Classes: PascalCaseAttribute (With the Attribute at the end. Don't worry about having to use the entire name though, compiler lets you cut the Attribute at the end when using the attribute.)
vocal thorn
static cedar
#

Nah, don't. Just follow the naming convention when the compiler notification gets annoying. UnityChanLOL

#

I do snake_case for my variables.

vocal thorn
#

Okay?? Slightly confused now

#

but thanks nevertheless

static cedar
#

There's just some people that wants you to stick to those guidelines as much as possible. I'd prefer to stick to whats right for me.

vocal thorn
gaunt ice
#

you can have your own set of naming convention

static cedar
median mortar
#

Hi guys, how do I assign Meshes/Materials from a ScriptableObject?

...
[SerializeField] ArrowSO type;
...
private void OnEnable() {
        MeshFilter meshFilter = this.gameObject.AddComponent<MeshFilter>();
        MeshRenderer meshRenderer = this.gameObject.AddComponent<MeshRenderer>();
        meshFilter.mesh = type.meshFilter.mesh;
        meshRenderer.material = type.meshRenderer.material;
}
public class ArrowSO : ScriptableObject
{
    public BowSM.EArrowType _ArrowType;
    public MeshFilter meshFilter;
    public MeshRenderer meshRenderer;
    public Material material;
}

Doesn't work like that, Filter/Renderer are still none in the inspector...

static cedar
vocal thorn
#

nukoKiss_1 ty !!

rare basin
teal viper
#

Assuming you're talking about the SO fields

static cedar
rare basin
#

lol

static cedar
#

I don't think i'll be a programmer for work though. But i can bend myself in work.

gaunt ice
#

i suggest you follow the naming standard actually, it is easier to read some source code of standard libraries

static cedar
#

That's just the bare-minimum.

rare basin
#

also when you share code to public

#

when they are adapted to standards

#

it is much easier to read your code

#

instead of your own naming conventions

teal viper
#

Some conventions are widely accepted in the developer community. If you go against them, it would be more difficult to get help.

static cedar
#

Are there standards on how you sort the members of a struct/class/interface?

#

(Top to bottom)

  • Constructor
  • Fields
  • Properties
  • Methods
  • Private Methods
  • Static Methods
  • Operators
  • Nested class or something
#

I guess? UnityChanThink

teal viper
#

There aren't really that I'm aware of, but most people just end up having a similar layout.

#

fields and properties at the top and methods in the bottom/

gaunt ice
#

usually i will align them manually to reduce padding space
in cpp you can put variables in header, left the methods in other file

#

same as c

static cedar
median mortar
# teal viper I don't see you assigning these fields anywhere.

I'm having an ArrowSO, that hat some Meshes and Materials, created several of them for different Arrow Types
Now I want to assign the different Meshes and Materials to just one Arrow Object, that can change it's appearance/behaviour depending on the SO given to it.

public class Arrow : MonoBehaviour,IArrow
{
    #region StateMachine
    ...
    #endregion
    #region ArrowSpecifics
    [SerializeField] ArrowSO type;
    #endregion
    ...
    private void OnEnable() {
        MeshFilter meshFilter = this.gameObject.AddComponent<MeshFilter>();
        MeshRenderer meshRenderer = this.gameObject.AddComponent<MeshRenderer>();
        meshFilter.mesh = type.meshFilter.mesh;
        meshRenderer.material = type.meshRenderer.material;
    }
    ...
}
static cedar
#

I think i'd prefer you to paste the entire !code.

eternal falconBOT
median mortar
# teal viper Okay. So what's the problem?

That my Meshes and Materials assigned to the SO aren't assigned to my added components on the Arrow GameObject using the Arrow class.
How do I assign the Meshes and Materials specified in my SO to my Arrow GameObject properly?

teal viper
median mortar
teal viper
#

Well, the error pretty much explains it

median mortar
#

Yeah, thanks anyway 😄

old gorge
#

Hi, I've seen a few resources that suggest to use the Animator built-in state machines liberally for when you need a FSM even if it has nothing to do with animations.
Is this a common practice ?

lavish terrace
#

unity editor cancels all assigned List<> contents when entering playing mode from editing mode any idea why ?

teal viper
#

maybe even update

lavish terrace
#

yea the thing is non exist

#

update ? hmmm

teal viper
#

You're clearing it or creating a new list

#

share the code

lavish terrace
#

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class BossKilledScript : MonoBehaviour
{
public GameObject RewardUI;
public BossScript bossScript;
public LootSystemScript lootSystemScript;

public List<KilledRewardScript> RewardsUI = new List<KilledRewardScript>();
public List<RewardScriptableObjects> Rewards = new List<RewardScriptableObjects>();

public bool Rewarded = false;

void Start()
{
    bossScript = GameObject.FindGameObjectWithTag("Boss").GetComponent<BossScript>();
    lootSystemScript = GameObject.FindGameObjectWithTag("LootSystem").GetComponent<LootSystemScript>();
}

void Update()
{
    if (bossScript.BossKilled == true && Rewarded == false)
    {
        Rewarding();
    }
}

void Rewarding()
{
    RewardUI.SetActive(true);

    int RewardNum = 0;
    foreach (RewardScriptableObjects Reward in Rewards)
    {

        if (lootSystemScript.ItemID[Reward.ItemId] == false)
        {
            int RewardRNG = Random.Range(1, 101);

            if (Rewards[RewardNum].RNG >= RewardRNG)
            {
                lootSystemScript.ItemID[Reward.ItemId] = true;
                RewardNum += 1;
                RewardsUI[RewardNum].ItemImage.sprite = Rewards[RewardNum].RewardIcon;
            }
            else
            {
                RewardNum += 1;
            }
            Debug.Log(Reward.DisplayName + " " + lootSystemScript.ItemID[Reward.ItemId]);
        }
    }

    Rewarded = true;
}

}

teal viper
#

!code

eternal falconBOT
lavish terrace
#

it is a bit messy in here

#
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class BossKilledScript : MonoBehaviour
{
    public GameObject RewardUI;
    public BossScript bossScript;
    public LootSystemScript lootSystemScript;

    public List<KilledRewardScript> RewardsUI = new List<KilledRewardScript>();
    public List<RewardScriptableObjects> Rewards = new List<RewardScriptableObjects>();

    public bool Rewarded = false;

    void Start()
    {
        bossScript = GameObject.FindGameObjectWithTag("Boss").GetComponent<BossScript>();
        lootSystemScript = GameObject.FindGameObjectWithTag("LootSystem").GetComponent<LootSystemScript>();
    }

    void Update()
    {
        if (bossScript.BossKilled == true && Rewarded == false)
        {
            Rewarding();
        }
    }

    void Rewarding()
    {
        RewardUI.SetActive(true);

        int RewardNum = 0;
        foreach (RewardScriptableObjects Reward in Rewards)
        {

            if (lootSystemScript.ItemID[Reward.ItemId] == false)
            {
                int RewardRNG = Random.Range(1, 101);

                if (Rewards[RewardNum].RNG >= RewardRNG)
                {
                    lootSystemScript.ItemID[Reward.ItemId] = true;
                    RewardNum += 1;
                    RewardsUI[RewardNum].ItemImage.sprite = Rewards[RewardNum].RewardIcon;
                }
                else
                {
                    RewardNum += 1;
                }
                Debug.Log(Reward.DisplayName + " " + lootSystemScript.ItemID[Reward.ItemId]);
            }
        }

        Rewarded = true;
    }
}

teal viper
#

Can you remove "using Unity.VisualScripting;" line?

lavish terrace
#

oh yea lemme try

#

same :/

teal viper
#

make the lists private

lavish terrace
#

wouldnt that make them unassignable in unity?

teal viper
#

Not if you use the proper [SerializeField] attribute

lavish terrace
#

aight

teal viper
#
[SerializeField] private List<KilledRewardScript> RewardsUI = new List<KilledRewardScript>();
lavish terrace
#

same :/

#

its not the update method

#

i removed it completly and still same problem

#

it caused by smth else

#

and it is not refrenced in other scripts aswell

teal viper
#

It can't be referenced if its private.

#

No errors in the console?

lavish terrace
#

no

#

i did change the name

#

and it got fixed

#

idk why

teal viper
lavish terrace
#

uhm not these but other ones

eager elm
lavish terrace
teal viper
lavish terrace
#

i think so i just need to find a solution for this new error

eager elm
lavish terrace
#

typical domino effect

lavish terrace
lavish terrace
teal viper
#

Why would you need both? lol

teal viper
lavish terrace
#

boss is the boss game object while bossScript is the bossScript

teal viper
#

How the heck are you gonna mix up scripts and gameobjects?

gaunt ice
#

do you know that monobehaviour has a field that reference back to the gameobject?

lavish terrace
#

idk its how i learnt unity

#

this.gameobject ?

gaunt ice
#

yes

lavish terrace
#

yea however if im gonna refrence the boss from the player script

gaunt ice
#

so you just need to reference the script

teal viper
#

You don't need the this. btw

whole isle
teal viper
lavish terrace
#

script, rigidbody, etc etc

whole isle
lavish terrace
#

is it that bad tho ?xd

teal viper
#

It's confusing

#

But you do you

lavish terrace
#

ah

#

its solo work after all so

gaunt ice
rare basin
#

no need for the if/else

royal ledge
#

Is Muliplayer event system known to be unreliable? I have it working perfectly instantiating a UI menu for each player, however if i load that scene from my lobby, it doesen't work at all, every component has been linked as it should be (Player root/First select) but i get no response from the UI even though the player inputs works absolutely fine, i don't know how to trouble shoot it. I can see it has the "first selected" selected but i can't get it to move at all.

whole isle
gaunt ice
#

actually i dont even know if you are in play mode or not....but i guess

rare basin
rare basin
#

do whatever you want with it

gaunt ice
#

then ofc update wont run unless this class is execute always

prime lodge
#

why this loop repeats infinitly
i wanted to make it repeat only one time

royal ledge
#

Aren't components just code visualized in unityxD?

whole isle
rare basin
gaunt ice
#

technically everything is code and visualized by your gpu finally sent to screen

eternal falconBOT
eager elm
rare basin
#

if you want to do something just one time?

prime lodge
#

yes

whole isle
rare basin
#

you can replace it or not

teal viper
whole isle
gaunt ice
#

no

rare basin
#

it's just simplier than having if/else

#

i showed you alternative for that

gaunt ice
#

read what i had said

rare basin
#

not related to your issue

whole isle
#

ok i understand now

eager elm
# prime lodge yes

you can set dead to false, or even better have another bool that you set to true once you call the code you want to run only once.

whole isle
#

do u know how i can attempt to solve the issue

gaunt ice
#

turn on play mode

eager elm
whole isle
#

mb guys when i start the game i does work

#

soz

eager elm
# whole isle

Create a new method with all the code in your Update function and call it UpdateHeartDisplay()
Call that method in
Update() and OnValidate()
OnValidate() is called in the editor whenever you make changes to the script, so it will now also update before you enter playmode.

whole isle
#

why is there an issue idk how to fix it

#

why isnt this called player health

languid spire
teal viper
polar acorn
whole isle
polar acorn
whole isle
#

even thought when i go on it its called PlayerHealth

polar acorn
#

Show it

whole isle
polar acorn
#

The code

teal viper
#

this is file name

#

file name != type/class/script name

languid spire
#

inb4 it NewBehaviourScript

whole isle
polar acorn
polar acorn
#

It's like pulling teeth

teal viper
polar acorn
#

The. Lid.

gaunt ice
#

the class inside the PlayerHealth.cs, show the class together with file name
and
!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

whole isle
#

im trynna call the PlayHealth script into the dealing damage script

polar acorn
whole isle
#

that player health

polar acorn
#

Fix that

teal viper
#

Does that look like PlayerHealth?

whole isle
#

mb i thought u can just rename it

teal viper
#

You can rename it now to the proper name.

whole isle
#

yh i chanhed it thx

languid spire
rare basin
rare basin
# whole isle

also you might want to restructure your code architecture

#

SlimeDealingDamage, what if you have skeleton and zombie and more enemy types?

#

will you do SkeletonDealingDamage ZombieDealingDamage etc for each?

#

you can make generic DamageDealer class for example and just set different parameters for each enemy (via scritpable objects or directly in the inspector), you can then make other classes based on this class for Boss for example, and with overriding certain functions etc

whole isle
#

thx for the tip ill change that

#

the charachter not taking damage ive looked at the code and console

#

and cant figure out what to do

modest dust
#

Why have an Update method when you can do all of that within TakeDamage method

verbal dome
# whole isle

Start putting Debug.Logs in your methods to see if they are even running

whole isle
modest dust
#

Also check your damage field within the inspector to check if it's actually non-zero

modest dust
#

Then do a Osmal said

whole isle
#

do i have to go here

verbal dome
whole isle
#

or is reading better

verbal dome
#

You should learn to read the docs first, yes

#

The video might have some useful tips but start with docs always

whole isle
#

for my code do i debug.log("Player")

#

nvm

hallow heath
#

this is the first time i got null reference error but no details. I cannot figure out what scripts causing this error. why this happening?

gaunt ice
#

turn on the stacktrace?

whole isle
modest dust
#

To see if it even calls that method

verbal dome
#

Yeah but add some text to it so its easier to identify rather than just a number.
$"Health after TakeDamage: {health}" or "Health after TakeDamage: " + health

tawdry mirage
#

i'm trying to precalculate circle segment mults by chord.
each step increases chord length by 0.001 and it is just array for 1000 doubles.
the problem is that with chord length close to zero, central angle in radians is close to Pi, and it decreases as chord length increases, it should be opposite, rigth?

for (int i = 0; i < lengthMultsByChord.Length; i++)
{
    if (i == 0) continue;
    double chordLength =  1d * i / lengthMultsByChord.Length;
    double centralAngleRad = 2 * Math.Acos(chordLength / 2);
    double centralAngle = centralAngleRad * 180 / Math.PI;
    lengthMultsByChord[i] = ((centralAngle / 360) * 2 * Math.PI);
}

i think i can just inverse angle, but how it works?
assuming r = 1

verbal dome
#

But the main idea is to see if the functions are running at all @whole isle

whole isle
#

and it dosent decrease

verbal dome
hallow heath
whole isle
polar acorn
#

What are you expecting that to do

whole isle
#

some1 told me

polar acorn
whole isle
#

i guess i misunderstood

polar acorn
#

At no point did anyone tell you to try to log a function

whole isle
swift crag
#

You were told to log to check if the function was being called.

whole isle
#

k i changed it

tawdry mirage
#

Debug.Log("it works");

whole isle
#

ohhh so if the function works it will say itworks

swift crag
whole isle
#

makes sense now

#

okay i understand

whole isle
modest dust
#

Also reading the docs is helpful

swift crag
#

you can also pass a second argument as the "context" of the log. clicking on the log entry will take you to the context object in the hierarchy.

#
Debug.Log("I worked", gameObject);
#

(or in the project window, if it's an asset)

#

I have some editor scripts that check for any invalid assets

#

e.g. I forgot to give something a description

#

it'll log a warning, and clicking the warning will take me to the bad asset

whole isle
rich adder
#

which is invalid on an if statement makes if statement pointless

whole isle
#

k i got rid of it

#

imma run the code and check console

swift crag
#

Restart your editor.

#

that's a problem on unity's end

#

There's a bug with the code that draws graphs (like for animators, I think) that makes it spew those errors

polar acorn
whole isle
rich adder
rich adder
#

wtf

whole isle
#

its gone now somehow

#

the message is still there actually but the game loaded

#

this is the only thing i get

#

but i dont think it related

rich adder
# whole isle

you have empty Animation Event on your animation clip

whole isle
polar acorn
#

Yeah that sounds like a good way to reset the animator state

whole isle
#

nothing shows up in console log

rich adder
polar acorn
whole isle
#

still nothing

polar acorn
#

Then nothing ever calls TakeDamage

whole isle
#

oof

#

i got no clue what to do

rich adder
verbal dome
#

Next check if OnCollisionEnter2D is being run and log the other object/its tag too

whole isle
#

have u guys look at my code

#

does it work

#

for taking half away

verbal dome
#

Put some thought into it

whole isle
#

i tried doing bothj

#

collison2d and collisom

#

then i tried doing Collison2D by itself

#

ill try playuer

modest dust
#

Trying random things won't help

verbal dome
#

You are accessing the tag right above it. I didnt tell you to log the collision itself, but the tag.
Also a comma is not how you print multiple values here

whole isle
whole isle
verbal dome
#

Im so confused how you come up with this random stuff from simple instructions

whole isle
#

😭

verbal dome
#

Probably best if you read everything 4 times

#

Log the tag and name of the object you are colliding with

whole isle
#

wdym when u say tag

gaunt ice
#

.tag

whole isle
#

oh

polar acorn
whole isle
#

i thought it was a terminology

#

mb

rich adder
# whole isle i thought it was a terminology
 private void OnCollisionEnter2D(Collision2D collision)
    {
        Debug.Log($"Hit object: {collision.gameObject} with tag: {collision.gameObject.tag}");
    }```
if you're curious about $, its called [String Interpolation](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated)
whole isle
#

nothing happeningggg

rich adder
whole isle
#

what the diffrence between Kinematic rigid boddy trigger and the 3rd 1

merry spade
#

Sorry if this is the wrong channel, but I think the "beginner" channel could help me with everything so, I am trying to add a package through Git URL but its not working, I tried adding a manifest line but then there is written, that I need to have Git installed on my System, so I installed it and added it in my system environment variables. But still its not working... please help me

slender nymph
meager sentinel
#

Someone knows how to place the IDE for modding a game in VSC? Idk if it's the same for unity, since i have it installed and no errors show for unity (It's a unity game obviously, and idk if i am on the wrong channel, if i am please lead me to the channel where i should be)

whole isle
slender nymph
whole isle
#

k im pretty sure it does

slender nymph
#

rather than being "pretty sure" you can just look at its collider and find out

median mortar
#

Hi guys, how can I use a ParticleSystem defined on an ScriptableObject on my GameObject?
Having a ParticleSystem that holds a reference to a flame prefab

public class ArrowSO : ScriptableObject
{
    public ParticleSystem ParticleSystem;
}

Want to instantiate the ParticleSystem hold by the SO and play it on my arrow, but watching in debug _ParticleSystem stays stopped

public class Arrow : MonoBehaviour,IArrow
{
    ...

    [SerializeField] ArrowSO _Type;
    Awake(){
    ...
    if(Type.ParticleSystem != null)    
    {

        _ParticleSystem = Instantiate(_Type).ParticleSystem;
        _ParticleSystem.Play();
    }
    ...
}

How can I use a ParticleSystem defined on a ScriptableObject?

whole isle
#

yh it is each time i click the sword then the clollider turns on

slender nymph
#

that's not what trigger collider means. there is a checkbox that is literally called Is Trigger on the collider

whole isle
#

its turned on

slender nymph
meager sentinel
subtle canyon
subtle canyon
meager sentinel
median mortar
slender nymph
rich adder
#

dam im slow to send today

eager elm
whole isle
#

i think this is my problem

polar acorn
whole isle
median mortar
whole isle
#

i thought the ticks were suppose to be like that

eager elm
subtle canyon
# slender nymph no, i just know how to read

So you are telling me that the moment he said modding you went to the rules and checked if his message didnt break any rules? I dont think anybody does that. You can only say that instantly when you know that rule from before

slender nymph
#

i've also been here long enough that i know modding is not permitted. and if you knew how to read you would know that i wasn't even the person who pointed out that modding isn't permitted here, i just pointed out that they were wrong about modding not being mentioned in the rules

polar acorn
median mortar
eager elm
polar acorn
#

it's not hard to find

median mortar
subtle canyon
eager elm
polar acorn
whole isle
median mortar
wintry quarry
polar acorn
subtle canyon
polar acorn
#

Instantiate clones an entire GameObject, so you can pass in the object or anything on it

median mortar
whole isle
#

@rich adder soz for the tag but i went through the entire thing and couldnt find the problem

polar acorn
slender nymph
polar acorn
rich adder
subtle canyon
#

Also I wasnt even talking to you @polar acorn

whole isle
#

for slime

#

player

languid spire
whole isle
#

preachh

polar acorn
# whole isle

Okay so you didn't follow the instructions on the page

whole isle
#

i did

#

i changed it to continus

subtle canyon
rich adder
#

not referring to that at all

#

you're using wrong method for your collider types..

languid spire
polar acorn
subtle canyon
whole isle
#

i wam working in 2D

rich adder
#

Trigger or Collision

polar acorn
whole isle
#

collison message

rich adder
#

and are you using colliders or triggers?

polar acorn
rich adder
#

this will never work with OnCollisionEnter

polar acorn
#

Do you know what a trigger is

#

Do you notice how both of your objects have both a rigidbody and a trigger

slender nymph
#

they are also both kinematic so even if is trigger was disabled for both that wouldn't even be the right one

polar acorn
whole isle
polar acorn
#

And notice how that's an empty box

#

meaning it will not work with this function

whole isle
#

so what do i ned to do

polar acorn
#

it's not magic, all those changes mean things

ivory bison
whole isle
#

ill remove trigger

#

on slime

#

to make it a rigid boddy]

polar acorn
#

You've been here for days coding by successive approximation, you need to actually do some guided learning on !learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

polar acorn
whole isle
#

i just wanna finsih this health systme

rich adder
whole isle
#

and slime

subtle canyon
# whole isle so i should remove triggers for my player body

Bro I think instead of just asking for help and copy pasting other's codes you can learn and write the code yourself.
If you are having a problem you can ask here but you are practically having these guys babysit you which is not appropriate at all.

whole isle
#

i promise

hollow carbon
#

when i start my game i cant see my spaceship

#

so how could i do the backround transparent so that i could see the game objects?

#

the image should be on the Backround

slender nymph
#

first, this is a code channel. second, you're not really providing enough context

hollow carbon
#

be mad

verbal dome
#

Did you mistype "my bad" or are you being a dick

hollow carbon
slender nymph
#

someone clearly doesn't want help

hollow carbon
#

bro i just only ask a Question

untold idol
languid spire
hollow carbon
hollow carbon
untold idol
#

Markus wreakin havoc in the Unity Discord Server

hollow carbon
#

what?

hollow carbon
languid spire
hollow carbon
#

ok but why are these people so toxic here

languid spire
#

nothing toxic about it. There are rules, we obey those rules, so must you

summer stump
polar acorn
spark ravine
#

Lol literally just did the Unity Tutorial Create with Code:

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

public class MoveForward : MonoBehaviour
{
    public float speed;

    void Update()
    {
        transform.Translate(transform.forward * Time.deltaTime * speed);
    }
}

For some reason the object doesent move along the local z axis, but rather the world z axis.
Thought transform.forward is local and Vector3. forward is global and sometimes it works like that too...

rich adder
#

afaik Translate default is self no ?

solemn fractal
#

Hey guys.. was checking here on how to communicate or transfer data between scenes.. and found some ways to do it.. any tips or best practices on that? Never done it and I might need to do it now first time. thank you!

swift crag
subtle canyon
swift crag
#

You're correct in that transform.forward is the forward direction of the transform and Vector3.forward is global.

spark ravine
#

aka last script that did the same

wild cargo
swift crag
#

Show us that last script, then.

spark ravine
# swift crag Link us to the tutorial page you're on.
Unity Learn

Overview: In this lesson, you will allow the player to launch the projectile through the scene. First you will write a new script to send the projectile forwards. Next you will store the projectile along with all of its scripts and properties using an important new concept in Unity called Prefabs. The player will be able to launch the projectil...

solemn fractal
subtle canyon
swift crag
#

transform.forward is a vector pointing in the forward direction of the transform. The vector is a world-space vector.

#

transform.Translate interprets the vector you give it in local-space, by default.

spark ravine
#

ty didn't know that

swift crag
#

So transform.Translate(Vector3.forward) moves you forwards by 1 unit in your forward direction

subtle canyon
spark ravine
#

never used transform. Translate

swift crag
#

transform.Translate(transform.forward) will be unpredictable

#

Suppose you're pointing straight up

spark ravine
#

always jsut used transform... += ... xD

swift crag
#

transform.forward will be an up-vector: [0, 1, 0]

spark ravine
#

or mostly rigidbodys

subtle canyon
swift crag
#

Passing that to Translate will move you in your local up direction

wild cargo
swift crag
#

which will make you move sideways

#

It'll work perfectly if you aren't rotated at all

#

in that case, local-space and world-space directions agree exactly

#

and transform.forward will be equal to Vector3.forward

#

That's why your code sometimes worked

spark ravine
#

yeah lol xD

#

ty

swift crag
#

A vector, by itself, doesn't have any context

#

Vector3.forward interpreted as a world-space vector points in the world +Z direction. Vector3.forward interpreted as a local-space vector points in your +Z direction

spark ravine
#

ok and when the function itself usees local space it is reversed I guess?

swift crag
#

well, in that case, you got some weird double-conversion going on

#

oops, free cube

swift crag
#

These are the same thing

#

You wound up doing this

#
var a = transform.forward;
var b = transform.TransformDirection(a);
#

b is...extra-transformed

#

it doesn't really make sense

spark ravine
#

ah ok got it XD

swift crag
#
var a = transform.InverseTransformDirection(transform.forward);
var b = Vector3.forward;
#

these are also identical, btw

#

Transform* goes from local to world space. InverseTransform* goes from world to local space

old gorge
verbal dome
swift crag
#

yeah, it is a state machine

verbal dome
#

Probably not common because it is rarely spoken of

old gorge
#

ok thanks

languid spire
sage mirage
#

Hey, guys! I have a question. I want to pause and unpause my game whenever the game is running and it is not game over with an ESCAPE button how to do that?

#

So, when the game is over to not allow the player to interact with that button.

#
{
    if (Input.GetKeyDown(KeyCode.Escape))
    {
        if (pauseIsActive)
        {
            StartCoroutine(ResumeAfterDelay());
        }

        else 
        {
            StartCoroutine(PauseAfterDelay());
        }          
    }

}


IEnumerator ResumeAfterDelay()
{
    yield return new WaitForSecondsRealtime(pauseMenuScreenDelay);
    pauseIsActive = false;
    pauseMenuScreen.SetActive(false);
    audioManager.mainGameMusicAudioSource.UnPause();
    Time.timeScale = 1f;
    Debug.Log("Pause menu screen is disabled after delay!");
}

IEnumerator PauseAfterDelay()
{
    yield return new WaitForSecondsRealtime(pauseMenuScreenDelay);
    pauseIsActive = true;
    pauseMenuScreen.SetActive(true);
    audioManager.mainGameMusicAudioSource.Pause();
    Time.timeScale = 0f;
    Debug.Log("Pause menu screen is enabled after delay!");
}``` 
I have this code on my UI manager script here!
verbal dome
sage mirage
#

So, here is where I am interacting with that button and pausing and unpausing actually

#

I have made one time before this functionality but now I got confused!

rich adder
#

May I recommend a global event?

#

public static event Action<bool> OnGamePaused

#

then anything that needs to stop doing stuff, ie like UI you can disable interactor/raycast

#

unless I misunderstood the q sorry xD

sage mirage
rich adder
#

then anyscript that needs to know game is paused you subscibe to it in Enable

sage mirage
#

So, what that does actually can you please specify?

rich adder
eager elm
rich adder
#

OHH

#

ops.. i shall go grab my caffeine now..

eager elm
sage mirage
#

Yes that's what I want

rich adder
#

yeah def a bool but may I suggest enum instead ?

sage mirage
#

Yes!

rich adder
#

imo its cleaner to have your gamestate be enum

#

instead of a bunch of bools

#
public enum GameState { Playing, Menu, Paused, GameOver} //etc.
#

I usually have something like this with also an event OnStateChanged?.Invoke(currentGameState)

harsh owl
#

currently when i accelerate my car quickly stops because of the drag value of my rigidbody. how can i make my car not stop so quick without changing my drag values (cant change them because my suspensions wouldnt work well anymore), im using AddForce for accelerating the car

rich adder
swift crag
#

i bet it'd get too powerful and fling the car around

#

I suspect you just need to tune your suspension as well

#

maybe the suspension spring joints need more damping

#

I've been going through similar things recently

#

trying to find a good combination of parameters that doesn't just explode the object

harsh owl
#

whenever i fall and land its like constantly bouncing

swift crag
#

Damp the spring joints themselves

harsh owl
#

yea i just got it

summer stump
#

There is this
!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

summer stump
#

And good resources pinned to this channel

harsh owl
# swift crag Damp the spring joints themselves

quick side question, should i use an empty parent object for my car and attach the rigidbody and driving script to it or just have the carmesh be the main parent with all the scripts and the rigidbody?

swift crag
#

i prefer the former

#

(in general, not just when doing physics)

#

that makes it way easier to swap out the model

harsh owl
#

thanks

summer stump
#

Which one? Unity.learn?
Go to pathways and do the "essentials" pathway, then the "junior programmer" pathway

sage mirage
#

Hey, guys! I want to know when we declare a bool variable called gameIsActive what we mean when we want to use it somewhere in our code. I mean the game is active when the play mode is active or when the game is running like the player is playing the game?

#

This bool variable confuses me sometimes and I don't know in which cases to use it that's why I ask.

wintry quarry
sage mirage
#

I know that XD

#

I mean this specific variable. I mean where can I use it.

wintry quarry
#

what we mean when we want to use it somewhere in our code. I mean the game is active when the play mode is active or when the game is running like the player is playing the game?
I don't really understand this question. The scope of the variable really depends on where you declare it

#

You should learn about the various different types of variables in C#:

  • Member variables
  • Local variables

And modifiers like static etc.

#

As a general rule anything you do in code is something that will exist in your game program when it is running, The exception is if it's a serializeds variable somewhere you can then assign it in the editor/inspector.

vast matrix
#

Im following a ground check tutorial vid and in the vid he was able to see the BoxCast and I cant here is my code ``` void OnDrawGizmozs(){
Gizmos.color=Color.red;
Gizmos.DrawCube(transform.position-transform.up*maxdistance, BoxSize);
}
bool GroundCheck(){
if(Physics.BoxCast(transform.position, BoxSize, -transform.up, transform.rotation, maxdistance, LayerMask)){
return true;
}
else{
return false;
}
}

sage mirage
wintry quarry
#

gameIsActive sounds like some custom variable you made

vast matrix
wintry quarry
vast matrix
#

first time using them

wintry quarry
#

on scene view or game view

#

whichever you want to see

vast matrix
#

I dont see one

wintry quarry
#

top right

sage mirage
#

Public bool gameIsActive; when we declare it on our own

wintry quarry
#

you could have called it public bool ajlskhdlakjhrfelkjhrf;

rich adder
#

learn the enum like I suggested and set your gamestate with that @sage mirage

wintry quarry
#

it's just a normal bool variable

sage mirage
#

I mean when you call it with a name and you want to use it for something specific you will not call it fjdhvuduirth

wintry quarry
#

the variable will behave the same no matter what name it has

vast matrix
vast matrix
wintry quarry
vast matrix
#

nope

wintry quarry
#

You sure?

vast matrix
#

yes

#

ok thx

#

idk just following the tutorial

verbal dome
#

If someone suggested it and there is some context then ask whoever suggested it

vast matrix
#

welp I give up on this tutorial

#

Ill use another one ig

rich adder
vast matrix
# rich adder send tutorial

Learn how to use Boxcast to check if the player is grounded in Unity.
#unity3d #unity3dtutorial #unity2d #unitytutorial
You can get the code samples from
https://vionixstudio.com/2021/10/26/how-to-make-a-character-jump-in-unity/

TIMESTAMP
00:00 Introduction
00:36 Different ways to Ground Check
02:31 Ground Check in Unity 3D
08:14 BoxCast not w...

▶ Play video
rich adder
#

timestamp for boxcast

vast matrix
#

lemme try to find it

#

between 3:00 and 6:50 imma try to find the exact moment tho

#

about 4:10

rich adder
#

oh ig you did copy the same

rich adder
#

PlayerController

vast matrix
#

heres the full image

wintry quarry
#

it should be OnDrawGizmos

rich adder
vast matrix
#

so thats what ive been doing wrong

rich adder
#

oh nvm im too slow today

summer stump
vast matrix
#

Now that I actually got to see the boxcast if my player moves the boxcast also moves making it impossible for him to jump sometimes

blissful phoenix
ocean wolf
#

Is there a glaringly obvious reason the Scale of these GameObjects returned via method are incorrect and do not update whatsoever?

https://hastebin.com/share/inafimodum.csharp

rich adder
#

you're overwriting size each iteration

ocean wolf
#

so I need a Vector3[] for scale as well

languid spire
#

scale is set to the last value of the itteration, so yes if you want a scale per object

ocean wolf
#

thank you

languid spire
#

not sure why you have 2 identical loops though @ocean wolf

ocean wolf
#

@languid spire how so?

#

oh you mean for gameobjects and length/scales

languid spire
#
        for(int i = 0; i < TPRP.Length; i++){
            colliderLengths[i] = (point[i].transform.position - associated[i].transform.position).magnitude;
            scale = new Vector3(width, width, colliderLengths[i]);
        }

        for(int i = 0; i < TPRP.Length; i++) {
            go[i].transform.position = TPRP[i];
            go[i].transform.rotation = Quaternion.LookRotation(point[i].transform.position - associated[i].transform.position);
            go[i].transform.localScale = scale;
            go[i].GetComponent<MeshRenderer>().material = blue;
        }

make them one loop

ocean wolf
#

yeah idk why I haven't done yet

#

lmao

#

ty

languid spire
#

then your scale is ok

ocean wolf
#

@languid spire @rich adder cheers fellas

autumn tusk
#

why am i getting this error in particular? i dragged an item into the "spookyenemy" field

summer stump
#

Or you unassign the reference in awake or start

autumn tusk
#

this is my code

#
using System.Collections.Generic;
using UnityEngine;

public class tutorialSpawning : MonoBehaviour
{
    [SerializeField] public GameObject spookyenemy;
    [SerializeField] GameObject spookyscaryskull;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            Instantiate(spookyenemy,transform.position,Quaternion.identity);
            Destroy(spookyscaryskull);
        }
    }
}
summer stump
#

Then the first thing I said

#

Type "t:tutorialSpawning" into the hierarchy search bar

autumn tusk
#

ok found it

#

there was an unused object sitting there

tender breach
#

I'm making a tetris-like game, but when the pieces aren't 0 degrees, they don't fall down.

timber tide
#

probably worth it to post some script of the problem

tender breach
#

Me?

slender nymph
# tender breach Me?

yes, but please screenshot what your code looks like in your IDE to get started

#

you didn't do that yesterday when it was requested of you

tender breach
slender nymph
#

this is not your ide

short hazel
#

Lord almighty that code style

slender nymph
tender breach
summer stump
tender breach
#

What?

slender nymph
#

why am i not surprised it's vs code after seeing this god awful formatting

short hazel
#

Put it all on one line at this point

slender nymph
# tender breach

also i can see you didn't listen to a thing that was told to you yesterday considering you're still trying to use the individual components of transform.rotation as if they are actually in degrees

tender breach
#

How do I fix that?

slender nymph
#

at this point it would be quicker and easier if you just started over and learned the basics first

short hazel
#

And focus especially on code style while learning, please

blissful phoenix
eternal needle
polar acorn
eternal needle
#

This is a special case, no one is reading that code

languid spire
#

I must say, that is probably the worst block of code I have ever seen and that is saying a great deal

tough lagoon
#

Hah sadly me too

polar acorn
#

At least the variables aren't all sequential single letters

zenith cypress
#

Don't give them ideas catFone

timber tide
#

cant say my first tetris game looked all too well haha

tough lagoon
#

My favorite part is that it's a screenshot. You literally have to review it as is 😄

slender nymph
#

in all fairness i did specifically request a screenshot so we could see if they are using a configured IDE. and of course they are using vs code and screenshot it in a way that doesn't make that very clear

rich adder
#

tobe fair to VSCode even that formats your code with C# devkit

#

idk wassup with theirs

tough lagoon
#

I'll leave it at - at least they are trying and didn't copy it from chatgpt

languid spire
#

I'll say one thing for their code formatting, at least the misplaced ; was blindingly bleeding obvious

queen adder
#

i get some fps drop because of this scene what can i do for optimization

rich adder
#

probably what lagging

queen adder
timber tide
#

is it on a terrain

cosmic dagger
#

First time I've seen that code format structure. Sheesh . . .

queen adder
#

and water

#

thing

timber tide
#

grass should be somewhat optimized, but the verts would still add up

#

ideally I'd look into baking the fort meshes together

rich adder
#

yea terrain grass is just billboard yes?

#

is fort static ?

#

that should at least bake it into a whole mesh

timber tide
#

oh yeah static should work (probably better if you don't want to deal with the culling)

queen adder
#

how can i do static

rich adder
#

also do occlusion culling

#

so you only render what you see

sly wasp
#

Hey
I made a “private Coroutine deathPlayer”
And then to call it I did
deathPlayer = StartCoroutine(DeathPlayer(“Animation));

That works fine, but to stop it I did
StopCoroutine(deathPlayer);
The coroutine did not stop

eternal falconBOT
sly wasp
rich adder
sly wasp
#

I don’t see the point in using that since it will show the same thing

queen adder
#

i couldnt find this section

slender nymph
languid spire
frosty hound
rich adder
sly wasp
slender nymph
#

well what you've posted would be a compile error

languid spire
#

well that line of code will not even ccompile

sly wasp
rocky canyon
slender nymph
frosty hound
sly wasp
#

Meant to put that

#

Ok

#

I’ll show it then

frosty hound
#

But anyway, not interested in people who are resistant to help. Hopefully someone else can.

eternal needle
#

That is why you just show your code properly from the start. You cannot show 2 lines of code then claim all is correct. If all is correct then you dont have an issue

frosty hound
#

(But likely you're calling the coroutine multiple times 🏃‍♂️)

sly wasp
polar acorn
sly wasp
slender nymph
#

you never bother checking if the coroutine is already running when you go to start it

languid spire
#

damn, are we having a 'bad code day' or what?

slender nymph
#

that is also a gigantic mess of conditions

sly wasp
sly wasp
#

I mistyped it

rich adder
#

the parameter is the last thing they're prob referring to

languid spire
#

I meant your code, have you never heard of caching GetComponent?

sly wasp
#

Why would I need to

rich adder
#

or caching soundclips..

visual hedge
#

any reason why my editor / game stopped seing OnRightClickEvent? It was working just fine and then suddenly (no idea what I did wrong) it stopped working and rightclick event doesn't get registered at all

sly wasp
rich adder
#

ironic

languid spire
modest dust
#

Like dear lord, it's been a while since I've seen this many in one place

rich adder
#

sfx.GetComponent<AudioSource>().PlayOneShot(Resources.Load<AudioClip>("sfx/Hr_run_jump"));

this can literally be
someAudioSource.PlayOneShot(Hr_run_jump);

#

or hell use a dictionary/lists of Sfx someAudioSource.PlayOneShot(soundFxDict[c_run_jump]);

sly wasp
#

I meant of mentioning audio clips

#

At the top

rich adder
#

You can literlly load those in from resources

#

just in awake

#

put them in dictionary

#

lookup each sound by const of names or something

#

do something else other than what you're doing now lol

slender nymph
dry tendon
#

Hello everyone! I'm working on a Unity project and need help creating a custom function in C#. I want it to behave like Start or Update but with a 3-second delay after the game starts. Is there a recommended way to do this and allow different scripts to define their own behavior for this function, similar to Start? I've tried Invoke but seek a solution that supports different implementations in various scripts. Any advice or examples would be appreciated! Thanks!

#

Did i express good myself?

rich adder
#

coroutine

#

update can work too ig but with a timer

#

then invoke an event to sub to

golden otter
#

for delayed functions Invoke should be enough tho

dry tendon
#

hmm... i want to do it on many scripts... so my intention is like to create function like start , for example delayedStart, callable from every scripts just one time from each script... idk if i'm expressing good myself...

rich adder
#

I try to stay away from unity's invoke

golden otter
rich adder
#

/slow

#

idk if its still like that

#

I dont use it

eternal needle
golden otter
#

oh right

dry tendon
timber tide
#

Using forces (rigidbodies), I'm looking for a way to generate a very specific radius of gravity instead of a lesser field of gravity over an area. Would that be possible or should I just consider doing my own transformation logic

slender nymph
#

fun fact but you can turn Start into a coroutine and just put a delay right inside of it if you need to

dry tendon
#

i'll first try it with a corrutine to try... thanks @slender nymph @rich adder @eternal needle @golden otter 🙂

safe carbon
#

void OnCollisionEnter(Collision collision) {

  if (collision.collider != null)
  {
      rb.velocity = new Vector2(0f, 0f);
  }

}

#

am i using it wrong

rich adder
#

yes

#

is your rigidbody 2D ?

golden otter
rich adder
#

its prob cause its a 2D game

safe carbon
#

yes

#

its a 2d game

rich adder